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
}
}
|
|
|
|
|