Last active
June 5, 2019 18:51
-
-
Save irlperu/5ec34b03ac48c4bb9bf91732c6b49dac to your computer and use it in GitHub Desktop.
Get Server Status (Running / Deallocated) in a Resource Group for
This file contains hidden or 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
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