Users: 30k; Pages Per Session: 2.5p; Avg. Session Duration: 1:35mi
TechDevOps.com
Explore Tools
{Featuring Microsoft Technologies + Enterprise Data + Cloud Computing}



Azure Powershell Get all Virtual Machines Status in a Subscription
by BF (Senior MSSQL Operations - Enterprise, Cloud, Strategy)
2016-09-19








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:

Login-AzureRmAccount


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

}

}