Hi @Bombbe ,
The probable reason for this error is you might be trying to connect to VM from runbook in an unsupported way.
To get Windows or Linux VM's OS information from runbook, you may leverage Invoke-AzVMRunCommand cmdlet and run the OS related commands remotely.
Sample steps to follow:
- Create a storage account, container and upload 2 blobs i.e., scripts one each for Windows (xxx.ps1 file) and Linux (xxx.sh file). Make sure the content of the scripts is as shown in below screenshots.
- Create a basic runbook as shown in below screenshot.
- Start the runbook and then you would get the Windows and Linux VM's OS info as shown in below screenshot.
Please find the sample runbook code below for easy usage:
$connectionName = "AzureRunAsConnection"
$servicePrincipalConnection = Get-AutomationConnection -Name $connectionName
$ConnectToAzAccount = Add-AzAccount -ServicePrincipal -TenantId $servicePrincipalConnection.TenantId -ApplicationId $servicePrincipalConnection.ApplicationId `
-CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint
$StorageAccountName = "xxxxxxxxxxxxx"
$StorageAccountKey = "xxxxxxxxxxxxxx=="
$ContainerName = "xxxxxxxxxxxxxxx"
$BlobName_Win = "xxxxxxxxxxxx.ps1"
$BlobName_Linux = "xxxxxxxxxxxx.sh"
$RG_VM = "xxxxxxxxxxxxxxxxxx"
$VM_Name_Win = "xxxxxxxxxx"
$VM_Name_Linux = "xxxxxxxxx"
$InvokeCmd_Id_Win = "RunPowerShellScript"
$InvokeCmd_Id_Linux = "RunShellScript"
$AzStorage = New-AzStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
$AzStorageContext = $AzStorage.Context
$GetBlobContent_Win = Get-AzStorageBlobContent -Container $ContainerName -Blob $BlobName_Win -Destination ($Env:temp+"/vm-os-capture-info.ps1") -Context $AzStorageContext -Force
$InvokeRunCmdOutput_Win = Invoke-AzVMRunCommand -ResourceGroupName $RG_VM -VMName $VM_Name_Win -CommandId $InvokeCmd_Id_Win -ScriptPath ($Env:temp+"/vm-os-capture-info.ps1")
$OSCaptionOutput_Win = $InvokeRunCmdOutput_Win.Value[0].Message
Write-Output "OS of $VM_Name_Win"
Write-Output $OSCaptionOutput_Win
$GetBlobContent_Linux = Get-AzStorageBlobContent -Container $ContainerName -Blob $BlobName_Linux -Destination ($Env:temp+"/vm-os-capture-info-linux.sh") -Context $AzStorageContext -Force
$InvokeRunCmdOutput_Linux = Invoke-AzVMRunCommand -ResourceGroupName $RG_VM -VMName $VM_Name_Linux -CommandId $InvokeCmd_Id_Linux -ScriptPath ($Env:temp+"/vm-os-capture-info-linux.sh")
$OSCaptionOutput_Linux = $InvokeRunCmdOutput_Linux.Value[0].Message
Write-Output "OS of $VM_Name_Linux"
Write-Output $OSCaptionOutput_Linux
Also note that you can improve this basic runbook to even more advanced one by
- adding foreach loop in script so that it works for multiple Windows and multiple Linux VM's
- adding Automation variable to get Storage key in a secured way
- formatting the output in better way to see Windows and Linux OS info in more organized way
- etc.