Modules/Inventory/ARIAPIInv.psm1
function Get-ARIAPIResources { $Token = az account get-access-token --only-show-errors --output json | ConvertFrom-Json $header = @{ 'Authorization' = 'Bearer ' + $Token.accessToken } $AzURL = 'management.azure.com' $ResourceHealthHistoryDate = (Get-Date).AddMonths(-12) $APIResults = @() $VMLocations = $Resources | Where-Object {$_.Type -in 'microsoft.compute/virtualmachines','microsoft.compute/virtualmachinescalesets'} foreach ($Sub in $Subscri) { #ResourceHealth Events $url = ('https://' + $AzURL + '/subscriptions/' + $Sub + '/providers/Microsoft.ResourceHealth/events?api-version=2022-10-01&queryStartTime=' + $ResourceHealthHistoryDate) $ResourceHealth = Invoke-APIRequest -url $url -header $header #Support Tickets $url = ('https://' + $AzURL + '/subscriptions/' + $Sub + '/providers/Microsoft.Support/supportTickets?api-version=2020-04-01') $SupTickets = Invoke-APIRequest -url $url -header $header #Quotas $Locations = ($VMLocations | Where-Object {$_.subscriptionId -eq $Sub} | Group-Object -Property Location).name $Quotas = @() foreach ($loc in $Locations) { $url = ('https://' + $AzURL + '/subscriptions/' + $Sub + '/providers/Microsoft.Compute/locations/'+ $loc +'/providers/Microsoft.Quota/usages?api-version=2023-02-01') $Quotas += Invoke-APIRequest -url $url -header $header } #Maintenances $url = ('https://' + $AzURL + '/subscriptions/' + $Sub + '/providers/Microsoft.Maintenance/publicMaintenanceConfigurations?api-version=2023-09-01-preview') $Maintenances = Invoke-APIRequest -url $url -header $header #Managed Identities $url = ('https://' + $AzURL + '/subscriptions/' + $Sub + '/providers/Microsoft.ManagedIdentity/userAssignedIdentities?api-version=2023-01-31') $Identities = Invoke-APIRequest -url $url -header $header #Advisor Score $url = ('https://' + $AzURL + '/subscriptions/' + $Sub + '/providers/Microsoft.Advisor/advisorScore?api-version=2023-01-01') $ADVScore = Invoke-APIRequest -url $url -header $header #Availability Status $url = ('https://' + $AzURL + '/subscriptions/' + $Sub + '/providers/Microsoft.ResourceHealth/availabilityStatuses?api-version=2024-02-01') $AvailStatus = Invoke-APIRequest -url $url -header $header $tmp = @{ 'Subscription' = $Sub; 'ResourceHealth' = $ResourceHealth; 'SupportTickets' = $SupTickets; 'Quotas' = $Quotas; 'Maintenance' = $Maintenances; 'ManagedIdentities' = $Identities; 'AdvisorScore' = $ADVScore; 'AvailabilityStatus' = $AvailStatus } $APIResults += $tmp } Remove-Variable -Name VMLocations #VM Reservation $url = 'https://management.azure.com/providers/Microsoft.Capacity/reservations?api-version=2022-11-01' $Reservation = Invoke-APIRequest -url $url -header $header $Body = @{ reportType = "OverallSummaryReport" subscriptionList = @($Subscri) carbonScopeList = @("Scope1") dateRange = @{ start = "2024-05-01" end = "2024-05-30" } } $url = 'https://management.azure.com/providers/Microsoft.Carbon/carbonEmissionReports?api-version=2023-04-01-preview' #$url = 'https://management.azure.com/providers/Microsoft.Carbon/queryCarbonEmissionDataAvailableDateRange?api-version=2023-04-01-preview' $APIResult = Invoke-RestMethod -Uri $url -Headers $header -Body ($Body | ConvertTo-Json) -Method POST -ContentType 'application/json' $APIResult.value } |