Skip to content

Instantly share code, notes, and snippets.

@irlperu
Last active June 5, 2019 18:51
Show Gist options
  • Save irlperu/5ec34b03ac48c4bb9bf91732c6b49dac to your computer and use it in GitHub Desktop.
Save irlperu/5ec34b03ac48c4bb9bf91732c6b49dac to your computer and use it in GitHub Desktop.
Get Server Status (Running / Deallocated) in a Resource Group for
Login-AzAccount -UseDeviceAuthentication
Get-AzContext
$VMs = @()
$RGs = Get-AzResourceGroup
foreach($RG in $RGs)
{
$VMs += Get-AzVM -ResourceGroupName $RG.ResourceGroupName -Status
}
# Take out the # at the end of the next line if you want to output to csv
# (get-azvm).HardwareProfile | Get-Member
# Get-AzVM | ConvertTo-Json -Depth 5
$VMs | Select-Object -Property Name, ResourceGroupName, PowerState, @{Name="VMSize"; Expression={$_.HardwareProfile | Select-Object -ExpandProperty vmSize } } # | Export-Csv -Path c:\temp\machines.csv -NoTypeInformation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment