Forum Discussion
Alan2022
Oct 28, 2022Iron Contributor
Get the list of unexpected failure in azure resource health history using Azure Rest API.
Hi Community,
Just Sharing.
Clear
$azContext = Get-AzContext
$azProfile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile
$profileClient = New-Object -TypeName Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient -ArgumentList ($azProfile)
$token = $profileClient.AcquireAccessToken($azContext.Subscription.TenantId)
$authHeader = @{
'Content-Type'='application/json'
'Authorization'='Bearer ' + $token.AccessToken
}
$subscriptionID = "<subscription id>"
$resourceGroupName = "<resource group name>"
$resourceProvider = "microsoft.compute"
$resourceType = "virtualmachines"
$resourceName = "<vm name>"
$contentType = "application/json;charset=utf-8"
$filter= "properties/availabilityState eq 'Unavailable'"
$url = "https://management.azure.com/subscriptions/$subscriptionID/resourceGroups/$resourceGroupName/providers/$resourceProvider/$resourceType/$resourceName/providers/Microsoft.ResourceHealth/availabilityStatuses?api-version=2018-07-01&$filter={$filter}"
$result = Invoke-RestMethod -Uri $url -Method Get -Headers $authHeader -ContentType $contentType
$result.value.properties | Where { $_.summary -like '*unexpected failure*' }
No RepliesBe the first to reply