Skip to content

Commit 0d2e275

Browse files
authored
Fillter subscriptions by tenant
1 parent a17c70c commit 0d2e275

3 files changed

Lines changed: 15 additions & 467 deletions

File tree

samples/manage/azure-arc-enabled-sql-server/modify-license-type/modify-arc-sql-license-type.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ if ($SubId -like "*.csv") {
195195
$subscriptions = Import-Csv $SubId
196196
}elseif($SubId -ne "") {
197197
Write-Output "Passed Subscription $($SubId)"
198-
$subscriptions = [PSCustomObject]@{SubscriptionId = $SubId} | Get-AzSubscription -TenantID $TenantId
198+
$subscriptions = Get-AzSubscription -SubscriptionId $SubId
199199
}else {
200-
$subscriptions = Get-AzSubscription -TenantID $TenantId
200+
$subscriptions = Get-AzSubscription | Where-Object { $_.TenantId -eq $tenantId }
201201
}
202202

203203
# Handle MachineName input (single or CSV)

samples/manage/azure-hybrid-benefit/modify-license-type/modify-azure-sql-license-type.ps1

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -169,23 +169,13 @@ $SqlVmLicenseType = if ($LicenseType -eq "LicenseIncluded") { "PAYG" } else { "A
169169
$modifiedResources = @()
170170

171171
# Determine the subscriptions to process: CSV file, single subscription, or all accessible subscriptions.
172-
try {
173-
if ($SubId -and $SubId -like "*.csv") {
174-
Write-Output "Gathering subscriptions from CSV file: $SubId"
175-
$subscriptions = Import-Csv -Path $SubId
176-
}
177-
elseif (($null -ne $SubId) -and $SubId -ne "") {
178-
Write-Output "Gathering subscription details for: $SubId"
179-
$subscriptions = @(az account show --subscription $SubId --output json | ConvertFrom-Json)
180-
}
181-
else {
182-
Write-Output "Gathering all accessible subscriptions..."
183-
$subscriptions = az account list --output json | ConvertFrom-Json
184-
}
185-
}
186-
catch {
187-
Write-Error "Error determining subscriptions: $_"
188-
exit 1
172+
if ($SubId -like "*.csv") {
173+
$subscriptions = Import-Csv $SubId
174+
}elseif($SubId -ne "") {
175+
Write-Output "Passed Subscription $($SubId)"
176+
$subscriptions = Get-AzSubscription -SubscriptionId $SubId
177+
}else {
178+
$subscriptions = Get-AzSubscription | Where-Object { $_.TenantId -eq $tenantId }
189179
}
190180

191181
# Build resource group filter if specified.
@@ -375,13 +365,13 @@ foreach ($sub in $subscriptions) {
375365
# Collect data before modification
376366
$modifiedResources += [PSCustomObject]@{
377367
TenantID = $TenantId
378-
SubID = $server.SubscriptionId
368+
SubID = $db.SubscriptionId
379369
ResourceName = $db.name
380370
ResourceType = $db.ResourceType
381371
Status = $db.State
382372
OriginalLicenseType = $db.licenseType
383-
ResourceGroup = $server.resourceGroup
384-
Location = $server.location
373+
ResourceGroup = $db.resourceGroup
374+
Location = $db.location
385375
}
386376

387377
if (-not $ReportOnly) {
@@ -405,13 +395,13 @@ foreach ($sub in $subscriptions) {
405395
# Collect data before modification
406396
$modifiedResources += [PSCustomObject]@{
407397
TenantID = $TenantId
408-
SubID = $server.SubscriptionId
398+
SubID = $pool.SubscriptionId
409399
ResourceName = $pool.name
410400
ResourceType = $pool.ResoureType
411401
Status = $pool.State
412402
OriginalLicenseType = $pool.licenseType
413-
ResourceGroup = $server.resourceGroup
414-
Location = $server.location
403+
ResourceGroup = $pool.resourceGroup
404+
Location = $pool.location
415405
}
416406

417407
if (-not $ReportOnly) {

0 commit comments

Comments
 (0)