| 437-991-3573 | Data Engineering Services
Resources Tools
Experts in Microsoft SQL Server on Windows, Linux, Containers | Clusters, Always On, FCI | Migrations, Cloud, Performance

Azure Powershell Get all Virtual Machines Status in a Subscription
by BF (Principal Consultant; Architecture; Engineering)

Getting the status of a all your Virtual Machines is typically a necessary step prior to taking other actions such as Config changes,
Stop-AzureVM or Start-AzureVM. The below Powershell code will loop through all the Resource Groups in your Subscription and
output-formatted these columns & data - Resource Group | VM Name | Provisioning State | Status Code.

Powershell Code:

Step 1: Authenticate to Azure Portal:


Step 2: Select a Subscription:

Select-AzureRmSubscription -SubscriptionName "TST"

Step 3: Powershell Code to get VM ProvisioningState and StatusCode:

$RGs = Get-AzureRMResourceGroup | Select-Object -Property ResourceGroupName

foreach($RG in $RGs)

$VMs = Get-AzureRmVM -ResourceGroupName $RG.ResourceGroupName

foreach($VM in $VMs)

$col= %{[PSCustomObject]@{'Resource Group'=$RG.ResourceGroupName; 'VM Name'=$VM.Name; 'Provisioning State'=$VM.ProvisioningState; 'Status Code'=$VM.StatusCode}}

$col | ft