Azure Automation Modules and Runbooks PowerShell 7.2
Hi All,
A few days ago, i opened up my Runbooks on Azure Automation Account. It tells you that PowerShell 7.1 and Phyton 2.7 are no longer supportet and provides you with a Link
Until now the AZ PowerShell did not support the Management of PowerShell 7.x Modules you had to use some tricks like i documented here
With the latest AZ 11.2.0 PowerShell Modules you can now Manage the PowerShell Modules 5.1 and 7.2 of your Azure Automation Account.
Check the AZ PowerShell Module Version
Get-InstalledPSResource AZ
From the Azure Portal you still can install Modules for 5.1, 7.1 and 7.2
Connect with Azure and List the Automation Accounts - we’re using icewolfautomation in this Blog Article
#Connect to Azure
Connect-AzAccount -Tenant icewolfch.onmicrosoft.com
#Get Automation Account
Get-AzAutomationAccount
Let’s check the MicrosoftTeams PowerShell Module in the GUI - what a strange Version Number of the PowerShell 7.2 Module
You can only list PowerShell 5.1 and Powershell 7.2 Modules
###############################################################################
# Get-AzAutomationModule
# https://learn.microsoft.com/en-us/powershell/module/az.automation/get-azautomationmodule?view=azps-11.2.0
###############################################################################
#Get Modules
$accountName = 'icewolfautomation'
$rgName = 'RG_DEV'
$ModuleName = "MicrosoftTeams"
#Get 5.1 Module
$RuntimeVersion = "5.1" #5.1, 7.2
Get-AzAutomationModule -AutomationAccountName $accountName -ResourceGroupName $rgName -RuntimeVersion $RuntimeVersion | Where-Object {$_.Name -match "$ModuleName"}
#Get 7.2 Module
$RuntimeVersion = "7.2" #5.1, 7.2
Get-AzAutomationModule -AutomationAccountName $accountName -ResourceGroupName $rgName -RuntimeVersion $RuntimeVersion | Where-Object {$_.Name -match "$ModuleName"}
Let’s remove the PowerShell 7.2 MicrosoftTeams PowerShell Module
###############################################################################
# Remove-AzAutomationModule
# https://learn.microsoft.com/en-us/powershell/module/az.automation/remove-azautomationmodule?view=azps-11.2.0
###############################################################################
#Remove Module
$accountName = 'icewolfautomation'
$rgName = 'RG_DEV'
$ModuleName = "MicrosoftTeams"
$RuntimeVersion = "7.2" #5.1, 7.2
Remove-AzAutomationModule -AutomationAccountName $accountName -ResourceGroupName $rgName -Name $ModuleName -RuntimeVersion $RuntimeVersion
As you can see in the Azure Portal the PowerShell 7.2 Module has been removed
Let’s add the PowerShell 7.2 Module MicrosoftTeams
###############################################################################
# New-AzAutomationModule
# https://learn.microsoft.com/en-us/powershell/module/az.automation/new-azautomationmodule?view=azps-11.2.0
###############################################################################
#Add Module
$ModuleName = "MicrosoftTeams"
$moduleVersion = "5.9.0"
$RuntimeVersion = "7.2" #5.1, 7.2
New-AzAutomationModule -AutomationAccountName $accountName -ResourceGroupName $rgName -Name $moduleName -ContentLinkUri "https://www.powershellgallery.com/api/v2/package/$moduleName/$moduleVersion" -RuntimeVersion $RuntimeVersion
In the Azure Portal you can see that the Module is beeing installed
If we look in PowerShell we can see the “PrivisioningState” set to “Creating”
#Get Modules
$accountName = 'icewolfautomation'
$rgName = 'RG_DEV'
$ModuleName = "MicrosoftTeams"
#Get 7.2 Module
$RuntimeVersion = "7.2" #5.1, 7.2
Get-AzAutomationModule -AutomationAccountName $accountName -ResourceGroupName $rgName -RuntimeVersion $RuntimeVersion | Where-Object {$_.Name -match "$ModuleName"}
When the Installation has been finished in Azure Portal
We check again in PowerShell and can see the “PrivisioningState” set to “Succeeded”
#Get Modules
$accountName = 'icewolfautomation'
$rgName = 'RG_DEV'
$ModuleName = "MicrosoftTeams"
#Get 7.2 Module
$RuntimeVersion = "7.2" #5.1, 7.2
Get-AzAutomationModule -AutomationAccountName $accountName -ResourceGroupName $rgName -RuntimeVersion $RuntimeVersion | Where-Object {$_.Name -match "$ModuleName"}
Runbooks
It seems that the Commands for PowerShell 7.2 Runbooks are not quite ready.
Create a new PowerShell 7.2 Runbook
###############################################################################
# New-AzAutomationRunbook
# https://learn.microsoft.com/en-us/powershell/module/az.automation/new-azautomationrunbook?view=azps-11.2.0
###############################################################################
#Create Runbook
$accountName = 'icewolfautomation'
$rgName = 'RG_DEV'
$Name = 'PS7Runbook'
$Type = 'PowerShell72' #PowerShell,PowerShell72
New-AzAutomationRunbook -Name $Name -Type $Type -AutomationAccountName $accountName -ResourceGroupName $rgName
The Runbook has been created but is not yet published
Publish a Runbook
###############################################################################
# Publish-AzAutomationRunbook
# https://learn.microsoft.com/en-us/powershell/module/az.automation/publish-azautomationrunbook?view=azps-11.2.0
###############################################################################
#Publish Runbook
$accountName = 'icewolfautomation'
$rgName = 'RG_DEV'
$Name = 'PS7Runbook'
Publish-AzAutomationRunbook -Name $Name -ResourceGroupName $rgName -AutomationAccountName $accountName
The Runbok has been published
But there is no Source Code in it
Get Runbook
###############################################################################
# Get-AzAutomationRunbook
# https://learn.microsoft.com/en-us/powershell/module/az.automation/get-azautomationrunbook?view=azps-11.2.0
###############################################################################
$accountName = 'icewolfautomation'
$rgName = 'RG_DEV'
$Name = 'PS7Runbook'
Get-AzAutomationRunbook -Name $Name -ResourceGroupName $rgName -AutomationAccountName $accountName #-ErrorAction SilentlyContinue
Delete Runbook
###############################################################################
# Remove-AzAutomationRunbook
# https://learn.microsoft.com/en-us/powershell/module/az.automation/remove-azautomationrunbook?view=azps-11.2.0
###############################################################################
#Remove Runbook
$accountName = 'icewolfautomation'
$rgName = 'RG_DEV'
$Name = 'PS7Runbook'
Remove-AzAutomationRunbook -Name $Name -AutomationAccountName $accountname -ResourceGroupName $rgName -Force
Import Runbook from a *.ps1 File
###############################################################################
# Import-AzAutomationRunbook
# https://learn.microsoft.com/en-us/powershell/module/az.automation/import-azautomationrunbook?view=azps-11.2.0
###############################################################################
# Import Runbook
$accountName = 'icewolfautomation'
$rgName = 'RG_DEV'
$Name = 'PS7Runbook'
$Type = 'PowerShell72' #PowerShell,PowerShell72
$scriptContent = @'
#Connect to Exchange with Managed Identity
$tenant = "icewolfch.onmicrosoft.com"
Connect-ExchangeOnline -ManagedIdentity -Organization $tenant
#Get Accepted Domain
Get-AcceptedDomain | Format-Table DomainName, DomainType
#Disconnect Exchange Online
Disconnect-ExchangeOnline -Confirm:$False
'@
Set-Content -Path .\Temp\ScriptContent.ps1 -Value $ScriptContent
Import-AzAutomationRunbook -Path .\Temp\ScriptContent.ps1 -Name $Name -ResourceGroupName $rgName -AutomationAccountName $accountName -Type $Type
The Runbook has been imported - but it’s not Published yet
Publish a Runbook
###############################################################################
# Publish-AzAutomationRunbook
# https://learn.microsoft.com/en-us/powershell/module/az.automation/publish-azautomationrunbook?view=azps-11.2.0
###############################################################################
#Publish Runbook
$accountName = 'icewolfautomation'
$rgName = 'RG_DEV'
$Name = 'PS7Runbook'
Publish-AzAutomationRunbook -Name $Name -ResourceGroupName $rgName -AutomationAccountName $accountName
And now the Runbook also has Code
Regards
Andres Bohren