'Setting Azure Automation PowerShell Runtime version

I have set up a Azure Automation, connected to Github for source control.
Coding in vs.code, pushing script to github and then to Azure Automation.

However, all new scripts is set to Runtime version 5.1, with no option to change this setting.

In short, what are my options for setting runtime version for the Runbook?



Solution 1:[1]

Setting runtime version via API changes are not yet implemented. This is part of the GA backlog and the tentative ETA is Q2 CY22.

Source of the above information: https://docs.microsoft.com/en-us/answers/questions/637711/index.html

Solution 2:[2]

I posted an answer on the following GitHub issue but will post it here for convenience:

https://github.com/Azure/azure-powershell/issues/16399

The runbook has to be initialized and populated using REST API calls (the first two calls). It can be published using the intended Azure cmdlet call for doing so (the third call). This is just a work-around until they officially support creating the a PowerShell 7.1 runbook with Azure cmdlets.

Invoke-AzRestMethod -Method "PUT" -ResourceGroupName $ResourceGroupName -ResourceProviderName "Microsoft.Automation" `
    -ResourceType "automationAccounts" -Name "${AutomationAccountName}/runbooks/${RunbookName}" -ApiVersion "2017-05-15-preview" `
    -Payload "{`"properties`":{`"runbookType`":`"PowerShell7`", `"logProgress`":false, `"logVerbose`":false, `"draft`":{}}, `"location`":`"${Location}`"}"

Invoke-AzRestMethod -Method "PUT" -ResourceGroupName $ResourceGroupName -ResourceProviderName "Microsoft.Automation" `
    -ResourceType automationAccounts -Name "${AutomationAccountName}/runbooks/${RunbookName}/draft/content" -ApiVersion 2015-10-31 `
    -Payload "$scriptContent"

Publish-AzAutomationRunbook -Name $RunbookName -AutomationAccountName $AutomationAccountName -ResourceGroupName $ResourceGroupName

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 KrishnaG-MSFT
Solution 2 fullmetalcache