Created
April 29, 2020 10:48
-
-
Save SQLtattoo/3a844b0708cea2d2d6205ca24f701e8e to your computer and use it in GitHub Desktop.
Get all VM status from all Resource Groups
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-AzureVMStatus | |
{ | |
$RGs = Get-AzResourceGroup | |
foreach($RG in $RGs) | |
{ | |
$VMs = Get-AzVM -ResourceGroupName $RG.ResourceGroupName | |
foreach($VM in $VMs) | |
{ | |
$VMDetail = Get-AzVM -ResourceGroupName $RG.ResourceGroupName -Name $VM.Name -Status | |
$RGN = $VMDetail.ResourceGroupName | |
foreach ($VMStatus in $VMDetail.Statuses) | |
{ | |
$VMStatusDetail = $VMStatus.DisplayStatus | |
} | |
Write-Output "Resource Group: $RGN", ("VM Name: " + $VM.Name), "Status: $VMStatusDetail" `n | |
} | |
} | |
} | |
Get-AzureVMStatus |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment