-
Notifications
You must be signed in to change notification settings - Fork 0
/
ResourcesByRegion.ps1
34 lines (27 loc) · 1.3 KB
/
ResourcesByRegion.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Azure Resource Graph Query = resources | summarize instances = count() by type
# Export CSV Results to "ResourcesByRegion.csv"
# Modify ResourcesByRegion.ps1 with the Regions you want to check services for
# Run the PowerShell script with ./ResourcesByRegion.ps1
# The results will be appended in the same input CSV file "ResourcesByRegion.csv"
$locations = ("Global","United States","West US","West US 2","West US 3")
$result= @()
$csv = Import-Csv "ResourcesByRegion.csv"
$csv | Foreach-Object {
$providerNs = $_.TYPE
$resourceType = $_.TYPE
$splitpoint = $_.TYPE.IndexOf('/')
if ($splitpoint -gt -1) {
$providerNs = $_.TYPE.Substring(0, $splitpoint)
$resourceType = $_.TYPE.Substring($splitpoint + 1, $resourceType.Length - $splitpoint - 1)
}
$data = [PSCustomObject]@{
TYPE = $_.TYPE
INSTANCES = $_.INSTANCES
#ProviderNamespace = $providerNs
#ResourceType = $resourceType
Locations = ((((Get-AzResourceProvider -ProviderNamespace $providerNs).ResourceTypes | where ResourceTypeName -eq $resourceType).Locations | where {$locations -contains $_} | Sort-Object) -join ",")
}
$result += $data
Write-Output ($data | ft -HideTableHeaders | Out-String).Trim()
}
$result | Export-Csv -Delimiter "," -Path "ResourcesByRegion.csv"