Unknown powerstate status for Azure VM

cmcardle 1 Reputation point
2021-11-10T12:42:02.683+00:00

I have a powershell script that starts up a sequence of Azure VMs by:

  • Starting up a VM
  • Checking if the powerstate of the VM is running
  • Moving onto the next VM in the list

As of recently, VMs that are in the South Central US region seem to stick on the "Unknown" status and then script is stuck waiting for the status to update to running, and this could last from 5-60 mins.
The major issue is these machines need to be on by a certain time.

Is there any way around this?

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,831 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,517 questions
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. Purna Rao 26 Reputation points
    2021-11-11T17:53:15.403+00:00

    Sometimes, if extensions take more time than expected the VM state show unknows. But the extensions at background still continue to install and after extensions installation success, the vm status shows running

    1 person found this answer helpful.
    0 comments No comments

  2. Limitless Technology 39,601 Reputation points
    2021-12-17T15:34:39.513+00:00

    I find it interesting that you consult the main common errors within Azure, so you will know the cause and how to solve them.

    See these errors in the article link below:

    https://learn.microsoft.com/en-us/troubleshoot/azure/virtual-machines/error-messages

    ----

    --If the answer is helpful, please vote positively and accept the answer.--

    1 person found this answer helpful.
    0 comments No comments

  3. msrini-MSFT 9,281 Reputation points Microsoft Employee
    2021-11-10T16:54:17.613+00:00

    @cmcardle ,

    To identify what is the cause of status returned as "unknown" needs deeper investigation with the logs from your end. That requires a support ticket.

    For now, to mitigate your issue, you can change the logic. You can skip the second step to check the Powerstate running and proceed further. Once this script ran successfully, you can get the status of all the VMs which this script turns ON and if it is unknown, keep on checking the status every 30 mins till it show as running.

    The above suggestion is only a workaround, if you need to get a deeper investigation, proceed with the support ticket.

    Regards,
    Karthik Srinivas


  4. shiva patpi 13,251 Reputation points Microsoft Employee
    2021-11-10T16:59:08.22+00:00

    Hello @cmcardle ,
    As I don't have the commands/script which you are using , one of the suggestion is - If there is no dependency among the machines start sequence , can you try to start the machines first with out checking the status of the VMs and in the next iteration come back and do a status check. This way all the VMs will be started on time.

    Try out the below sample script:-

    try
    {
    $StartScriptBlock =
    {
    param($VMName,$RGName)
    Write-Host "Starting VM: " $VMName
    try{
    Start-AzVM -ResourceGroupName $RGName -Name $VMName -NoWait
    }
    catch{
    Write-Host "Error in Starting VM: " $VMName
    }
    }

    $StatusScriptBlock =
    {
    param($VMName,$RGName)
    Write-Host "Starting VM: " $VMName
    try{
    $status = Get-AzVM -ResourceGroupName $RGName -Name $VMName
    Write-Host $VMName ":" $status.ProvisioningState
    }
    catch{
    Write-Host "Error in Starting VM: " $VMName
    }
    }

    $StartVMJobs = @();
    $StatusVMJobs = @();
    $AllVMs = Get-AzVM
    #start all the machines
    foreach ($vm in $AllVMs)
    {
    $StartVMJobs += Start-Job -ScriptBlock $StartScriptBlock -ArgumentList $vm.Name,$vm.ResourceGroupName
    $StatusVMJobs += Start-Job -ScriptBlock $StatusScriptBlock -ArgumentList $vm.Name,$vm.ResourceGroupName
    }
    Write-Host "VM Start Jobs Started successfully"
    Wait-Job -Job $StartVMJobs | Out-Null
    Receive-Job -Job $StartVMJobs
    Write-Host "VM Start Jobs Completed successfully"

    Write-Host "VM Status Jobs Started successfully"
    Wait-Job -Job $StatusVMJobs | Out-Null
    Receive-Job -Job $StatusVMJobs
    Write-Host "VM Status Jobs Completed successfully"
    }
    finally
    {

    }

    Regards,
    Shiva.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.