azure-powershell
azure-powershell copied to clipboard
Cannot upload Powershell 7.1 module with Set-AzAutomationModule
Description
I can't figure out how to use Set-AzAutomationModule
to upload a module that targets Powershell 7.1.
Our module .psd1 contains:
PowerShellVersion = '7.1'
CompatiblePSEditions = 'Core'
Modules uploaded using Set-AzAutomationModule
are showing up in the module list targeting 5.1 instead of 7.1.
I don't see any cmdlet parameters that would be relevant to specifying the target platform.
Is there some way to make this work?
Issue script & Debug output
Irrelevant
Environment data
Name Value
---- -----
PSVersion 7.2.0
PSEdition Core
GitCommitId 7.2.0
OS Microsoft Windows 10.0.22000
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Module versions
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Script 2.6.1 Az.Accounts {Add-AzEnvironment, Clear-AzContext, Clear-AzDefault, Connect-AzAccount…}
Script 1.7.1 Az.Automation {Export-AzAutomationDscConfiguration, Export-AzAutomationDscNodeReportContent, Export-AzAutomationRunbook, Get-AzAutomationAccount…}
Error output
Irrelevant
Thank you for your reporting. Tagging and routing to the team member best able to assist.
@silverl Support for 7.1 is in preview and currently uses a separate API for managing modules via the portal. The existing PowerShell cmdlets are not updated to support them.
You could however make leverage the Invoke-AzRestMethod
cmdlet to perform the same calls as the portal in the meantime.
I see. Is implementing support for 7.1 on the roadmap? Any ETA on adding that to the PowerShell cmdlets?
Do we leave this open until it's resolved?
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @jaspkaur28.
Issue Details
Description
I can't figure out how to use Set-AzAutomationModule
to upload a module that targets Powershell 7.1.
Our module .psd1 contains:
PowerShellVersion = '7.1'
CompatiblePSEditions = 'Core'
Modules uploaded using Set-AzAutomationModule
are showing up in the module list targeting 5.1 instead of 7.1.
I don't see any cmdlet parameters that would be relevant to specifying the target platform.
Is there some way to make this work?
Issue script & Debug output
Irrelevant
Environment data
Name Value
---- -----
PSVersion 7.2.0
PSEdition Core
GitCommitId 7.2.0
OS Microsoft Windows 10.0.22000
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Module versions
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Script 2.6.1 Az.Accounts {Add-AzEnvironment, Clear-AzContext, Clear-AzDefault, Connect-AzAccount…}
Script 1.7.1 Az.Automation {Export-AzAutomationDscConfiguration, Export-AzAutomationDscNodeReportContent, Export-AzAutomationRunbook, Get-AzAutomationAccount…}
Error output
Irrelevant
Author: | silverl |
---|---|
Assignees: | PramodValavala-MSFT |
Labels: |
|
Milestone: | - |
@jaspkaur28 Could you share insights on any ETA for the above?
@silverl Support for 7.1 is in preview and currently uses a separate API for managing modules via the portal. The existing PowerShell cmdlets are not updated to support them.
You could however make leverage the
Invoke-AzRestMethod
cmdlet to perform the same calls as the portal in the meantime.
Hi, I stumbled upon this thread for same reasons (Automation and managed identity). How do I use the Invoke-AzRestMethod for this purpose specifically?
What is the apiversion I need to specify?
Is this the endpoint https://docs.microsoft.com/en-us/rest/api/automation/module/create-or-update
If so, I'm not sure I see any argument that specifies the target runtime.
@silverl @OfficeUnlimited There seems to be a separate endpoint which is like the one above except that instead of modules
it is powershell7Modules
. You can check the requests being sent by the browser when performing these operations from the portal.
The API Version used by the portal is 2019-06-01
.
Here is a sample request using Invoke-AzRestMethod
Invoke-AzRestMethod `
-Method PUT `
-SubscriptionId $subscriptionId `
-ResourceGroupName $rgName `
-ResourceProviderName Microsoft.Automation `
-ResourceType automationAccounts `
-Name $aaName/powershell7Modules/PSKubectl `
-ApiVersion 2019-06-01 `
-Payload '{"properties":{"contentLink":{"uri":"https://devopsgallerystorage.blob.core.windows.net/packages/pskubectl.0.13.0.nupkg"}}}'
@jaspkaur28 Could you share more insights here?
@PramodValavala-MSFT @silverl - Currently PS7.1 is only supported through the portal. API changes for ARM and PS cmdlets are not yet implemented. We are tracking this as part of PS7.1 GA. Tentative ETA is early Q2 CY22.
@jaspkaur28 Thanks for the update! I am reassigning this issue to you to share updates as you know more.
@silverl I hope the workaround should suffice until then.
The workaround will do, thank you.
Used the suggestion from @PramodValavala-MSFT and got it working. Below is a mostly complete example, minus error handling and filling in all the variable values:
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
Update on PS7.1 GA that's mentioned in one of the above comment: The tentative ETA is moved to Q4 CY22 as service is undergoing some of the major architecture level changes.
Used the suggestion from @PramodValavala-MSFT and got it working. Below is a mostly complete example, minus error handling and filling in all the variable values:
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
@fullmetalcache ; please, how the heck do i send a PowerShell JSON payload? what was your $scriptContent
?
@fluffy-cakes The $scriptContent can be anything. As simple as
$scriptContent = "Write-Output 'aa' `
Write-Output 'bb'"
The workaround has been provided in this PR
#please-close
@SnehaSudhirG ; what PR? i don't see any link. this is an issue, not a PR
Hi All,
I would like to see, that we can manage the Powershell Modules with the AZ PowerShell Module.
Until then, here is how you can Manage the PowerShell 7 Modules until then https://blog.icewolf.ch/archive/2022/11/19/how-to-manage-powershell-5-and-7-modules-on-azure.aspx
Regards Andres
Any updates on this? We still cannot create/update PowerShell 7 runbooks using Bicep
Any news ?
like to know the update as well, need powershell7 module feature via bicep/ARM
We are now in Q2 of 2023. Is there any update on full PowerShell 7 support in run books, including PS CmdLets/ARM template support to manage these?
How can this be closed when it seems like 7.1 modules aren't being handled at all either via the portal or powershell.
For those that have a need to create a runbook with PowerShell 7.2:
Invoke-AzRestMethod -Method "PUT" -ResourceGroupName $resourceGroupName -ResourceProviderName "Microsoft.Automation" `
-ResourceType "automationAccounts" -Name "${AutomationAccountName}/runbooks/${RunbookName}" -ApiVersion 2022-06-30-preview `
-Payload "{`"properties`":{`"runbookType`":`"PowerShell`",`"runtime`":`"PowerShell-7.2`", `"logProgress`":false, `"logVerbose`":false, `"draft`":{}}, `"location`":`"$($location)`"}"
Seems like you can't get this to work for modifying the runtime version of Python runbooks. Source control syncing is great, the inability to easily control runtime versioning is frustrating. Try to set to Python-3.8 get error signaling can only be set to 3.10, set to 3.10 get error that it can't be modified. ¯_(ツ)_/¯
Content : {"code":"BadRequest","message":"Runtime property is invalid for runbookType Python. Supported values are - Python-3.10."}
Content : {"code":"BadRequest","message":"Runbook Language cannot be modified."}
Manually create runbook without source control - NO PROBLEMS
Hello everyone, I managed to upload some 7.2 modules and here is the construct that helped me upload modules for 5.1, 7.1 & 7.2 for anyone whom this can help.
$AutomationAccountName = 'Your-AACC-for-modules'
$createRunbookParam = @{
Method = "PUT"
ResourceGroupName = 'Your-RG-With-AAcc'
ResourceProviderName = "Microsoft.Automation"
ResourceType = "automationAccounts"
}
$moduleInfo = @{
Name = 'Microsoft.Graph.Authentication'
Version = '2.1.0'
PSVersion = '7.2'
VersionIndependentLink = 'https://www.powershellgallery.com/api/v2/package/Microsoft.Graph.Authentication'
}
$moduleEndpointEnum = @{
'7.1' = 'powershell7Modules'
'7.2' = 'powershell7Modules'
'5.1' = 'Modules'
}
# payload with uri for module from gallery
$modulePayload = @{
properties = @{
contentLink = @{
uri = "$($moduleInfo.VersionIndependentLink)/$($moduleInfo.Version)"
}
}
} | ConvertTo-Json -Compress
# version of API that enables 7.1 as default and runtimeVersion uri variable for 7.2
$createRunbookParam.ApiVersion = '2019-06-01'
if($moduleEndpointEnum[$moduleInfo.PSVersion]){ $createRunbookParam.ApiVersion += '&runtimeVersion=7.2' }
# 'Your-RG-With-AAcc/powershell7Modules/Microsoft.Graph.Authentication?ApiVersion=2019-06-01&runtimeVersion=7.2'
Invoke-AzRestMethod @createRunbookParam -Name "${AutomationAccountName}/$($moduleEndpointEnum[$moduleInfo.PSVersion])/$($moduleInfo.Name)" -Payload $modulePayload
I'm sharing back my set of PowerShell functions for uploading either 7.1 or 7.2 Runbooks. Hat tip to @fullmetalcache, @ChrisNotABot and @PramodValavala-MSFT, thank you.
function Write-RestError {
param (
$result
)
Write-Output "Error creating runbook`n"
$result
# Convert the response content to a PowerShell object and write it
$parsedContent = $result.Content | ConvertFrom-Json
Write-Output "Code: $($parsedContent.code)"
Write-Output "Message: $($parsedContent.message)"
throw $result
}
function Publish-Runbook {
param (
[parameter(Mandatory = $true)]
[string] $RunbookPath,
[parameter(Mandatory = $true)]
[string] $ResourceGroupName,
[parameter(Mandatory = $true)]
[string] $AutomationAccountName,
[string] $Location,
[parameter(Mandatory = $true)]
[ValidateSet("PowerShell-7.1", "PowerShell-7.2")]
[string] $RunbookType
)
$ErrorActionPreference = "Stop"
# Load the file into a variable as a string
$scriptContent = Get-Content -Path $RunbookPath -Raw
# Get the name of the runbook from the filename portion of the $Path without the extenions.
$runbookName = Get-RunbookNameFromPath($RunbookPath)
# This call creates the runbook if it doesn't exist.
if ($RunbookType -eq "PowerShell-7.1") {
$result = Invoke-AzRestMethod -Method "PUT" -ResourceGroupName $ResourceGroupName -ResourceProviderName "Microsoft.Automation" `
-ResourceType "automationAccounts" -Name "${AutomationAccountName}/runbooks/${RunbookName}" -ApiVersion "2019-06-01" `
-Payload "{`"properties`":{`"runbookType`":`"PowerShell7`", `"logProgress`":false, `"logVerbose`":false, `"draft`":{}}, `"location`":`"${Location}`"}"
}
else {
$result = Invoke-AzRestMethod -Method "PUT" -ResourceGroupName $ResourceGroupName -ResourceProviderName "Microsoft.Automation" `
-ResourceType "automationAccounts" -Name "${AutomationAccountName}/runbooks/${RunbookName}" -ApiVersion "2022-06-30-preview" `
-Payload "{`"properties`":{`"runbookType`":`"PowerShell`", `"runtime`":`"PowerShell-7.2`", `"logProgress`":false, `"logVerbose`":false, `"draft`":{}}, `"location`":`"${Location}`"}"
}
if ($result.StatusCode -gt 202) {
Write-RestError -result $result
}
# This call creates the draft content of the runbook.
$result = Invoke-AzRestMethod -Method "PUT" -ResourceGroupName $ResourceGroupName -ResourceProviderName "Microsoft.Automation" `
-ResourceType automationAccounts -Name "${AutomationAccountName}/runbooks/${RunbookName}/draft/content" -ApiVersion "2019-06-01" `
-Payload "$scriptContent"
if ($result.StatusCode -gt 202) {
Write-RestError -result $result
}
# This call publishes the runbook.
Publish-AzAutomationRunbook -Name $runbookName -AutomationAccountName $AutomationAccountName -ResourceGroupName $ResourceGroupName
Write-Output "Successfully published runbook: $runbookName`n"
}
function Get-RunbookNameFromPath {
param (
[string] $Path
)
# Get the name of the runbook from the filename portion of the $Path without the extenions.
return (Get-Item $Path).Name.Replace(".ps1", "")
}
function Publish-AllRunbooks {
param (
# Validate that $Path is a folder that exists.
[parameter(Mandatory = $true)]
[ValidateScript({ Test-Path $_ -PathType Container })]
[string] $Path,
[parameter(Mandatory = $true)]
[ValidateSet("PowerShell-7.1", "PowerShell-7.2")]
[string] $RunbookType
)
# Get a list of all Runbooks matching only *.ps1 files.
$ErrorActionPreference = "Stop"
$files = Get-ChildItem -Path $Path -Recurse -Filter *.ps1
# Append successes to array named $successes
# Append failures to array named $failures
$successes = @()
$failures = @()
foreach ($file in $files) {
$runbookName = Get-RunbookNameFromPath($file.FullName)
Write-Output "----------------------------------------"
Write-Output "Publishing runbook $runbookName`nResult:"
try {
Publish-Runbook -RunbookPath $file.FullName -RunbookType $RunbookType
$successes += $runbookName
}
catch {
Write-Host "Failed!" -ForegroundColor Red
$failures += $runbookName
}
}
# Output the successes first and then the failures so they'll be seen.
Write-Host "Successes:" -ForegroundColor Green
$successes | ForEach-Object { Write-Host $_ -ForegroundColor Green }
# Write the failures in red.
Write-Host "Failures:" -ForegroundColor Red
$failures | ForEach-Object { Write-Host $_ -ForegroundColor Red }
}
For those that have a need to create a runbook with PowerShell 7.2:
Invoke-AzRestMethod -Method "PUT" -ResourceGroupName $resourceGroupName -ResourceProviderName "Microsoft.Automation" ` -ResourceType "automationAccounts" -Name "${AutomationAccountName}/runbooks/${RunbookName}" -ApiVersion 2022-06-30-preview ` -Payload "{`"properties`":{`"runbookType`":`"PowerShell`",`"runtime`":`"PowerShell-7.2`", `"logProgress`":false, `"logVerbose`":false, `"draft`":{}}, `"location`":`"$($location)`"}"
@ChrisNotABot where did you find that 2022-06-30-preview api documented?