Created
February 7, 2021 08:59
-
-
Save ChendrayanV/9c2d8fae6c6f56820a61e24421f70fca to your computer and use it in GitHub Desktop.
Azure Virtual Machines Power State (Resource Graph Query)
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
$Query = "Resources | |
| where type =~ 'microsoft.compute/virtualMachines' | |
| project id, VMName = tostring(name), Location = tostring(location), | |
ResourceGroup = tostring(resourceGroup), | |
SubscriptionId = tostring(subscriptionId), | |
OSType = tostring(properties.storageProfile.osDisk.osType), | |
PowerState = iff( | |
tostring( | |
split( | |
properties.extended.instanceView.powerState.code, '/' | |
)[1] | |
) != '', tostring(split(properties.extended.instanceView.powerState.code, '/')[1]), 'transitioning' | |
)" | |
$PageSize = 1000 | |
$Iteration = 0 | |
$SearchParams = @{ | |
Query = $($Query) | |
First = $PageSize | |
} | |
[System.Collections.ArrayList]$Results = @() | |
do { | |
$Iteration += 1 | |
$PageResults = Search-AzGraph @searchParams -Verbose | |
$SearchParams.Skip += $pageResults.Count | |
$Results.AddRange($pageResults) | |
} while ($PageResults.Count -eq $PageSize) | |
$Results |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment