-
Notifications
You must be signed in to change notification settings - Fork 2
/
Get-AzsUserSubscriptionQuotaLimit.ps1
109 lines (81 loc) · 3.06 KB
/
Get-AzsUserSubscriptionQuotaLimit.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<#
.Synopsis
Calculate the limit of Quotas per user subscriptions and export this limit as json file.
#>
$ErrorActionPreference = "stop"
$QuotaList = @(
'AvailabilitySetCount',
'CoresLimit',
'VmScaleSetCount',
'VirtualMachineCount',
'StandardManagedDiskAndSnapshotSize',
'PremiumManagedDiskAndSnapshotSize',
'NumberOfStorageAccounts',
'CapacityInGb',
'MaxPublicIpsPerSubscription',
'MaxVnetsPerSubscription',
'MaxVirtualNetworkGatewaysPerSubscription',
'MaxVirtualNetworkGatewayConnectionsPerSubscription',
'MaxLoadBalancersPerSubscription',
'MaxSecurityGroupsPerSubscription'
)
$Subscriptions = Get-AzsUserSubscription
$Subscriptions | ForEach-Object {
$QuotaSummary = [ordered]@{}
$QuotaList | ForEach-Object {
$QuotaSummary[$_] = $null
}
$Subscription = $_
$ResourceGroup = $Subscription.OfferId.Split('/')[4]
$OfferName = $Subscription.OfferId.Split('/')[8]
$Offer = Get-AzureRmResource -ResourceGroupName $ResourceGroup -Name $OfferName -ExpandProperties -ResourceType Microsoft.Subscriptions.Admin/offers
$BasePlan = $offer.Properties.basePlanIds
$BasePlanDetails = Get-AzsPlan -ResourceId $BasePlan[0]
$BasePlanDetails.QuotaIds | ForEach-Object {
$Quota = ""
$ResourceProvider = $_.Split('/')[4]
if ( $ResourceProvider -eq 'Microsoft.Compute.Admin' ){
$Quota = Get-AzsComputeQuota -ResourceId $_
}
if ( $ResourceProvider -eq 'Microsoft.Storage.Admin' ){
$Quota = Get-AzsStorageQuota -ResourceId $_
}
if ( $ResourceProvider -eq 'Microsoft.Network.Admin' ){
$Quota = Get-AzsNetworkQuota -ResourceId $_
}
$QuotaList | ForEach-Object {
if ( $Quota.$_ -ne $null ){
$QuotaSummary[$_] += $Quota.$_
}
}
}
$AddonPlans = $null
$AddonPlans = $offer.Properties.addonPlans
$AddonPlans | ForEach-Object {
$AddonPlan = $_.planId
$AddonPlanDetails = $null
$AddonPlanDetails = Get-AzsPlan -ResourceId $AddonPlan
$AddonPlanDetails.QuotaIds | ForEach-Object {
$Quota = ""
$ResourceProvider = $_.Split('/')[4]
if ( $ResourceProvider -eq 'Microsoft.Compute.Admin' ){
$Quota = Get-AzsComputeQuota -ResourceId $_
}
if ( $ResourceProvider -eq 'Microsoft.Storage.Admin' ){
$Quota = Get-AzsStorageQuota -ResourceId $_
}
if ( $ResourceProvider -eq 'Microsoft.Network.Admin' ){
$Quota = Get-AzsNetworkQuota -ResourceId $_
}
$QuotaList | ForEach-Object {
if ( $Quota.$_ -ne $null ){
$QuotaSummary[$_] += $Quota.$_
}
}
}
}
Write-output "User Subscription Id: $($Subscription.SubscriptionId)"
$QuotaSummary | ft -AutoSize
$FileName = $Subscription.SubscriptionId + "_" +"$($Subscription.Owner)" + ".json"
$QuotaSummary | ConvertTo-Json | Out-File $FileName -Force
}