Himanshu Bakshi
Himanshu Bakshi

Reputation: 1

Quota Usage and limits for 80+ Azure subscriptions in a single report

I have 80+ Azure EA Subscriptions and I would like to know if there is a script where I can dump multiple subscription quota limit in one file using PowerShell. I am getting the output somehow in the format but I am unable to identify to which subscription the output belongs to. Because I have 80+ subscriptions under single tenant.

Script:

#Connect-AzAccount

$region=""

$subscriptions = Get-AzSubscription

Foreach ($sub in $subscriptions) {
#$context = (Get-AzSubscription | Out-GridView -Title 'Set subscription context' -PassThru)
#$sub1 = Set-AzContext -Subscription $context | Out-Null

Get-AzSubscription -SubscriptionName $sub.name | Set-AzContext

write-host "Azure context set for the subscription, `n$((Get-AzContext).Name)" -f green
 

($vm = Get-AzVMUsage -Location $region `
| select @{label='ResourceType';expression={$_.name.LocalizedValue}}, currentvalue, limit) `
#| Out-GridView -Title "Azure $region Region Compute Quota & Usage"
 
($storage = Get-AzStorageUsage -Location $region `
| select @{label='ResourceType';expression={$_.name}}, currentvalue, limit) `
#| Out-GridView -Title "Azure $region Region Storage Account Quota & Usage"
 
($network = Get-AzNetworkUsage -Location $region `
| select @{label='ResourceType';expression={$_.resourcetype}}, currentvalue, limit) `
#| Out-GridView -Title "Azure $region Network Quota & Usage"

$when=get-date -format 'yyyyMMdd-hhmm'

($usage = @("Azure $region Region Quota and usage, as of $when",$vm,"`n",$storage,"`n",$network) | ft) `
>> "usage-$region-$when.txt"
}

In the output of above script, I am not able to distinguish between the subscriptions. ,It does not provide the subscriptions corresponding to the data that is getting generated.

Looking for advise.

Upvotes: 0

Views: 672

Answers (1)

Jim Xu
Jim Xu

Reputation: 23141

Regarding the issue, please refer to the following code

Connect-AzAccount

$subscriptions = Get-AzSubscription

$region="eastasia"

$subscriptions = Get-AzSubscription

Foreach ($sub in $subscriptions) {

$context=Get-AzSubscription -SubscriptionName $sub.name | Set-AzContext

write-host "Azure context set for the subscription, `n$($context.Name)" -f green
 
($vm = Get-AzVMUsage -Location $region `
| select @{label='ResourceType';expression={$_.name.LocalizedValue}}, currentvalue, limit) `

 
($storage = Get-AzStorageUsage -Location $region `
| select @{label='ResourceType';expression={$_.name}}, currentvalue, limit) `

 
($network = Get-AzNetworkUsage -Location $region `
| select @{label='ResourceType';expression={$_.resourcetype}}, currentvalue, limit) `


$when=get-date -format 'yyyyMMdd-hhmm'

($usage = @("Azure $region Region Quota and usage in Subscription $($context.Subscription.Name), as of $when",$vm,"`n",$storage,"`n",$network) | ft) `
>> "usage-$region-$when.txt"

}

My output enter image description here

Upvotes: 1

Related Questions