How to check VM ready status for multiple VM's using a powershell script (around 120 VM's)

Ravi Kiran Moole 60 Reputation points
2025-06-10T07:11:07.83+00:00

How to check VM ready status for multiple VM's using a powershell script (around 120 VM's)

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
9,014 questions
{count} votes

Accepted answer
  1. Andreas Baumgarten 123.4K Reputation points MVP Volunteer Moderator
    2025-06-11T05:39:06.7166667+00:00

    Hi @Ravi Kiran Moole ,

    to get the PowerStatus and the Agent Status please try this script using the same text file for your VM list:

    $output = @()
    $list = Get-Content -Path "<path to your file\<name of the text file>.txt"
    foreach ($item in $list){
    $VMs = Get-AzVM -Name $item -Status
    foreach ($VM in $VMs) {
            $VM_status = Get-AzVM -Name $VM.Name -ResourceGroupName $VM.ResourceGroupName -Status
            $Row = "" | Select-Object Name, PowerState, ProvisioningState, VMAgent_Status, VMAgent_Version
            $Row.Name = $VM_status.Name
            $Row.PowerState = $VM.PowerState
            $Row.ProvisioningState = $VM.ProvisioningState
            $Row.VMAgent_Status = $VM_status.VMAgent.Statuses.DisplayStatus
            $Row.VMAgent_Version = $VM_status.VMAgent.VmAgentVersion
            $output += $Row
         }
    }
     $output | Format-Table
    
    

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards

    Andreas Baumgarten

    1 person found this answer helpful.
    0 comments No comments

4 additional answers

Sort by: Most helpful
  1. Andreas Baumgarten 123.4K Reputation points MVP Volunteer Moderator
    2025-06-10T07:28:02.02+00:00

    Hi @Ravi Kiran Moole ,

    maybe this helps to get started:

    Get-AzVM -status | Select-Object Name, PowerState, ProvisioningState
    
    

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards

    Andreas Baumgarten

    0 comments No comments

  2. Ravi Kiran Moole 60 Reputation points
    2025-06-10T07:30:51.2+00:00

    Hello @Andreas Baumgarten

    Could you please share more details on how to add around 120 VM's to the script and pull the required data or readiness state?

    Like i have a list of 120 VM's included in the DR activity and i want to check the status after the DR, so i need to add these list of 120 selected VM's only


  3. Andreas Baumgarten 123.4K Reputation points MVP Volunteer Moderator
    2025-06-10T07:40:03.6+00:00

    Hi @Ravi Kiran Moole ,

    if you have text file with the VM name in each line you can try this:

    $list = Get-Content -Path "<path to your file\<name of the text file>.txt"
    foreach ($item in $list) {
    Get-AzVM -Name $item -status | Select-Object Name, PowerState, ProvisioningState
    }
    
    

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards

    Andreas Baumgarten

    0 comments No comments

  4. Ravi Kiran Moole 60 Reputation points
    2025-06-11T06:01:52.1+00:00

    Thanks so much Andreas, that worked like charm!


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.