Wednesday, 21 December 2016

Powershell Script to view / check the status of VMs in a Subscription



Powershell Script to view / check the status of VMs in a Subscription



Login-AzureRmAccount

$RGs = Get-AzureRMResourceGroup

foreach($RG in $RGs)
{
    $VMs = Get-AzureRmVM -ResourceGroupName $RG.ResourceGroupName
    foreach($VM in $VMs)
    {
        $VMDetail = Get-AzureRmVM -ResourceGroupName $RG.ResourceGroupName -Name $VM.Name -Status
        foreach ($VMStatus in $VMDetail.Statuses)
        {
            #if($VMStatus.Code.CompareTo("PowerState/deallocated") -eq 0)
            if($VMStatus.Code -like "PowerState/*")
            {
                $VMStatusDetail = $VMStatus.DisplayStatus
            }
        }
        write-output $VM.Name $VMStatusDetail
    }
}



No comments:

Post a Comment

Get SSL Certificate Expiry Notification on Mail.

 There are multiple ways to get SSL Certification expiry details/alert. We all know if our SSL certificate get expire, how critical situatio...