@@ -41,7 +41,13 @@ if ($args[0] -ne $null) {
41
41
}
42
42
43
43
[System.Collections.ArrayList ]$usage = @ ()
44
- $usage += , (@ (" Subscription Name" , " Subscription ID" , " AHB Std vCores" , " AHB Ent vCores" , " PAYG Std vCores" , " PAYG Ent vCores" , " HADR Std vCores" , " HADR Ent vCores" , " Developer vCores" , " Express vCores" ))
44
+ if ($ec -eq $null ){
45
+ $usage += , (@ (" Subscription Name" , " Subscription ID" , " AHB Std vCores" , " AHB Ent vCores" , " PAYG Std vCores" , " PAYG Ent vCores" , " HADR Std vCores" , " HADR Ent vCores" , " Developer vCores" , " Express vCores" ))
46
+ }else {
47
+ $usage += , (@ (" Subscription Name" , " Subscription ID" , " AHB ECs" , " PAYG ECs" , " AHB Std vCores" , " AHB Ent vCores" , " PAYG Std vCores" , " PAYG Ent vCores" , " HADR Std vCores" , " HADR Ent vCores" , " Developer vCores" , " Express vCores" ))
48
+ }
49
+ $total = [pscustomobject ]@ {ahb_std = 0 ; ahb_ent = 0 ; payg_std = 0 ; payg_ent = 0 ; hadr_std = 0 ; hadr_ent = 0 ; developer = 0 ; express = 0 }
50
+
45
51
46
52
# Save the VM SKU table
47
53
$VM_SKUs = Get-AzComputeResourceSku
@@ -61,70 +67,70 @@ foreach ($sub in $subscriptions){
61
67
}
62
68
63
69
# Total counts of different license types
64
- $total = [pscustomobject ]@ {ahb_std = 0 ; ahb_ent = 0 ; payg_std = 0 ; payg_ent = 0 ; hadr_std = 0 ; hadr_ent = 0 ; developer = 0 ; express = 0 }
70
+ $subtotal = [pscustomobject ]@ {ahb_std = 0 ; ahb_ent = 0 ; payg_std = 0 ; payg_ent = 0 ; hadr_std = 0 ; hadr_ent = 0 ; developer = 0 ; express = 0 }
65
71
66
72
# Get all logical servers
67
73
$servers = Get-AzSqlServer
68
74
69
- # Get all SQL databadse resources in the subscription
75
+ # Get all SQL database resources in the subscription
70
76
$databases = $servers | Get-AzSqlDatabase
71
77
72
- # Get the databases with License Included and add to VCore count
78
+ # Process the vCore-based databases
73
79
foreach ($db in $databases ){
74
80
if ($db.SkuName -eq " ElasticPool" ) {continue }
75
81
76
82
if ($db.LicenseType -eq " LicenseIncluded" ) {
77
83
if ($db.Edition -eq " BusinessCritical" ) {
78
- $total .ahb_ent += $db.Capacity
84
+ $subtotal .ahb_ent += $db.Capacity
79
85
} elseif ($db.Edition -eq " GeneralPurpose" ) {
80
- $total .ahb_std += $db.Capacity
86
+ $subtotal .ahb_std += $db.Capacity
81
87
}
82
88
}else {
83
89
if ($db.Edition -eq " BusinessCritical" ) {
84
- $total .payg_ent += $db.Capacity
90
+ $subtotal .payg_ent += $db.Capacity
85
91
} elseif ($db.Edition -eq " GeneralPurpose" ) {
86
- $total .payg_std += $db.Capacity
87
- }$table
92
+ $subtotal .payg_std += $db.Capacity
93
+ }
88
94
}
89
95
}
90
96
91
97
# Get all SQL elastic pool resources in the subscription
92
98
$pools = $servers | Get-AzSqlElasticPool
93
99
94
- # Get the elastic pools with License Included and and add to VCore count
100
+ # Process the vCore-based elastic pools
95
101
foreach ($pool in $pools ){
96
102
if ($pool.LicenseType -eq " LicenseIncluded" ) {
97
103
if ($pool.Edition -eq " BusinessCritical" ) {
98
- $total .ahb_ent += $pool.Capacity
104
+ $subtotal .ahb_ent += $pool.Capacity
99
105
} elseif ($pool.Edition -eq " GeneralPurpose" ) {
100
- $total .ahb_std += $pool.Capacity
106
+ $subtotal .ahb_std += $pool.Capacity
101
107
}
102
108
}else {
103
109
if ($pool.Edition -eq " BusinessCritical" ) {
104
- $total .payg_ent += $pool.Capacity
110
+ $subtotal .payg_ent += $pool.Capacity
105
111
} elseif ($pool.Edition -eq " GeneralPurpose" ) {
106
- $total .payg_std += $pool.Capacity
112
+ $subtotal .payg_std += $pool.Capacity
107
113
}
108
114
}
109
115
}
110
116
111
117
# Get all SQL managed instance resources in the subscription
112
118
$instances = Get-AzSqlInstance
113
119
114
- # Get the SQL managed instances with License Included and add to VCore count
120
+ # Process the SQL managed instances with License Included and add to VCore count
115
121
foreach ($ins in $instances ){
116
122
if ($ins.InstancePoolName -eq $null ){
117
123
if ($ins.LicenseType -eq " LicenseIncluded" ) {
118
124
if ($ins.Sku.Tier -eq " BusinessCritical" ) {
119
- $total .ahb_ent += $ins.VCores
125
+ $subtotal .ahb_ent += $ins.VCores
120
126
} elseif ($ins.Sku.Tier -eq " GeneralPurpose" ) {
121
- $total .ahb_std += $ins.VCores
127
+ $subtotal .ahb_std += $ins.VCores
122
128
}
123
129
}else {
124
130
if ($ins.Edition -eq " BusinessCritical" ) {
125
- $total .payg_ent += $pool.Capacity
131
+ $subtotal .payg_ent += $pool.Capacity
126
132
} elseif ($ins.Edition -eq " GeneralPurpose" ) {
127
- $total .payg_std += $ins.Capacity
133
+ $subtotal .payg_std += $ins.Capacity
128
134
}
129
135
}
130
136
}
@@ -133,19 +139,19 @@ foreach ($sub in $subscriptions){
133
139
# Get all instance pool resources in the subscription
134
140
$ipools = Get-AzSqlInstancePool
135
141
136
- # Get the instance pools with License Included and add to VCore count
142
+ # Process the instance pools
137
143
foreach ($ip in $ipools ){
138
144
if ($ip.LicenseType -eq " LicenseIncluded" ) {
139
145
if ($ip.Edition -eq " BusinessCritical" ) {
140
- $total .ahb_ent += $ip.VCores
146
+ $subtotal .ahb_ent += $ip.VCores
141
147
} elseif ($ip.Edition -eq " GeneralPurpose" ) {
142
- $total .ahb_std += $ip.VCores
148
+ $subtotal .ahb_std += $ip.VCores
143
149
}
144
150
}else {
145
151
if ($ip.Edition -eq " BusinessCritical" ) {
146
- $total .payg_ent += $ip.Capacity
152
+ $subtotal .payg_ent += $ip.Capacity
147
153
} elseif ($ip.Edition -eq " GeneralPurpose" ) {
148
- $total .payg_std += $ip.Capacity
154
+ $subtotal .payg_std += $ip.Capacity
149
155
}
150
156
}
151
157
}
@@ -165,19 +171,19 @@ foreach ($sub in $subscriptions){
165
171
if ($ssis_ir.State -eq " Started" ){
166
172
if ($ssis_ir.LicenseType -like " LicenseIncluded" ){
167
173
if ($ssis_ir.Edition -like " Enterprise" ){
168
- $total .ahb_ent += $vcpu.value
174
+ $subtotal .ahb_ent += $vcpu.value
169
175
}elseif ($ssis_ir.Edition -like " Standard" ){
170
- $total .ahb_std += $vcpu.value
176
+ $subtotal .ahb_std += $vcpu.value
171
177
}
172
178
}elseif ($data.license -like " BasePrice" ){
173
179
if ($ssis_ir.Edition -like " Enterprise" ){
174
- $total .payg_ent += $vcpu.value
180
+ $subtotal .payg_ent += $vcpu.value
175
181
}elseif ($ssis_ir.Edition -like " Standard" ){
176
- $total .payg_std += $vcpu.value
182
+ $subtotal .payg_std += $vcpu.value
177
183
}elseif ($ssis_ir.Edition -like " Developer" ){
178
- $total .developer += $vcpu.value
184
+ $subtotal .developer += $vcpu.value
179
185
}elseif ($ssis_ir.Edition -like " Express" ){
180
- $total .express += $vcpu.value
186
+ $subtotal .express += $vcpu.value
181
187
}
182
188
}
183
189
}
@@ -201,33 +207,44 @@ foreach ($sub in $subscriptions){
201
207
202
208
if ($data.license -like " DR" ){
203
209
if ($data.sku -like " Enterprise" ){
204
- $total .hadr_ent += $data.vcpus
210
+ $subtotal .hadr_ent += $data.vcpus
205
211
}elseif ($data.sku -like " Standard" ){
206
- $total .hadr_std += $data.vcpus
212
+ $subtotal .hadr_std += $data.vcpus
207
213
}
208
214
}elseif ($data.license -like " AHUB" ){
209
215
if ($data.sku -like " Enterprise" ){
210
- $total .ahb_ent += $data.vcpus
216
+ $subtotal .ahb_ent += $data.vcpus
211
217
}elseif ($data.sku -like " Standard" ){
212
- $total .ahb_std += $data.vcpus
218
+ $subtotal .ahb_std += $data.vcpus
213
219
}
214
220
}elseif ($data.license -like " PAYG" ){
215
221
if ($data.sku -like " Enterprise" ){
216
- $total .payg_ent += $data.vcpus
222
+ $subtotal .payg_ent += $data.vcpus
217
223
}elseif ($data.sku -like " Standard" ){
218
- $total .payg_std += $data.vcpus
224
+ $subtotal .payg_std += $data.vcpus
219
225
}elseif ($data.sku -like " Developer" ){
220
- $total .developer += $data.vcpus
226
+ $subtotal .developer += $data.vcpus
221
227
}elseif ($data.sku -like " Express" ){
222
- $total .express += $data.vcpus
228
+ $subtotal .express += $data.vcpus
223
229
}
224
230
}
225
231
}
226
232
}
227
233
228
-
229
- $usage += , (@ ($sub.Name , $sub.Id , $total.ahb_std , $total.ahb_ent , $total.payg_std , $total.payg_ent , $total.hadr_std , $total.hadr_ent , $total.developer , $total.express ))
230
-
234
+ foreach ( $property in $total.psobject.properties.name ){
235
+ $total .$property += $subtotal .$property
236
+ }
237
+ if ($ec -eq $null ){
238
+ $usage += , (@ ($sub.Name , $sub.Id , $subtotal.ahb_std , $subtotal.ahb_ent , $subtotal.payg_std , $subtotal.payg_ent , $subtotal.hadr_std , $subtotal.hadr_ent , $subtotal.developer , $subtotal.express ))
239
+ }else {
240
+ $usage += , (@ ($sub.Name , $sub.Id , ($subtotal.ahb_std + $subtotal.ahb_ent * 4 ), ($subtotal.payg_std + $subtotal.payg_ent * 4 ), $subtotal.ahb_std , $subtotal.ahb_ent , $subtotal.payg_std , $subtotal.payg_ent , $subtotal.hadr_std , $subtotal.hadr_ent , $subtotal.developer , $subtotal.express ))
241
+ }
242
+ }
243
+
244
+ if ($ec -eq $null ){
245
+ $usage += , (@ (" Total" , $null , $total.ahb_std , $total.ahb_ent , $total.payg_std , $total.payg_ent , $total.hadr_std , $total.hadr_ent , $total.developer , $total.express ))
246
+ }else {
247
+ $usage += , (@ (" Total" , $null , ($total.ahb_std + $total.ahb_ent * 4 ), ($total.payg_std + $total.payg_ent * 4 ), $total.ahb_std , $total.ahb_ent , $total.payg_std , $total.payg_ent , $total.hadr_std , $total.hadr_ent , $total.developer , $total.express ))
231
248
}
232
249
233
250
$table = ConvertFrom-Csv ($usage | % { $_ -join ' ,' } )
0 commit comments