The RPC server is unavailable. (Exception from HRESULT: 0x800706BA) (Azure Runbook)

Bombbe 1,611 Reputation points
2021-03-01T13:33:19.587+00:00

Hi,
I'm running following command in Azure Runbook to servers in Azure:

Get-WmiObject -class Win32_OperatingSystem -cn $vm.Name | select Caption  

which should return server's operating system but now I'm getting error (capture taken from management workstation (Powershell)). I would like to save results as variable and use it later.

73055-caption.png

errors from Runbook log:

73018-rpc.png

73052-rpc-2.png

I also checked that needed service is running on host vm

73054-rpc-3.png

Was also able to get command work from my management workstation.

So issue should not really be directly that command but somehow it don't work with Azure Runbook.

If there are another commands that can get Azure vms operating system info with Runbook, I think it will also do the job for me. Using storageProfile.imageReference do not work for me because most of the servers are migrated which is why storageProfile.imageReference -> sku data is missing.

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,143 questions
0 comments No comments
{count} votes

Accepted answer
  1. tbgangav-MSFT 10,391 Reputation points
    2021-03-02T12:39:20.667+00:00

    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.

    73441-image.png

    73365-image.png

    73394-image.png

    • Create a basic runbook as shown in below screenshot.

    73396-image.png

    • Start the runbook and then you would get the Windows and Linux VM's OS info as shown in below screenshot.

    73397-image.png

    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.

1 additional answer

Sort by: Most helpful
  1. Mariusz Borys 11 Reputation points
    2021-10-01T14:21:45.033+00:00

    If I would like to download a zip file which I need for installation I am using the same commnad like this ?

    $BlobNameInstall_win = "agents-win.zip"

    $GetBlobContentInstall_Win = Get-AzStorageBlobContent -Container $ContainerName -Blob $BlobNameInstall_win -Destination ($Env:temp+"/agents-win.zip") -Context $AzStorageContext -Force

    I am asking because I am not able to find either sript or zip file in $env:temp when I logged in to the vm via rdp.

    I have found the path of where the files are being downloaded. Zip file was saved az ps1 file
    137418-image.png

    0 comments No comments