@@ -135,63 +135,6 @@ function Get-ApiopsLogLevel([string]$ScriptLogLevel) {
135135 }
136136}
137137
138- function Remove-KnownAutoSubscriptions {
139- param (
140- [Parameter (Mandatory )][string ]$SubscriptionId ,
141- [Parameter (Mandatory )][string ]$ResourceGroup ,
142- [Parameter (Mandatory )][string ]$ServiceName ,
143- [Parameter (Mandatory )][string ]$ScopeLabel
144- )
145-
146- Write-Host " Cleaning auto-created subscriptions in ${ScopeLabel} APIM..."
147- $listUri = " https://management.azure.com/subscriptions/$SubscriptionId /resourceGroups/$ResourceGroup /providers/Microsoft.ApiManagement/service/$ServiceName /subscriptions?api-version=2025-09-01-preview"
148- $listRaw = Invoke-MaskedAzCommand - Replacements @ {
149- $SubscriptionId = Protect-SubscriptionId - Value $SubscriptionId
150- $ResourceGroup = Protect-ResourceGroupName - Value $ResourceGroup
151- $ServiceName = Protect-ApimName - Value $ServiceName
152- } - Arguments @ (' rest' , ' --method' , ' get' , ' --url' , $listUri )
153-
154- if ($LASTEXITCODE -ne 0 -or -not $listRaw ) {
155- Write-Host " ⚠️ Could not list subscriptions for cleanup in ${ScopeLabel} "
156- return
157- }
158-
159- try {
160- $payload = $listRaw | ConvertFrom-Json
161- } catch {
162- Write-Host " ⚠️ Could not parse subscription list for cleanup in ${ScopeLabel} "
163- return
164- }
165-
166- $candidates = @ ($payload.value | Where-Object {
167- $name = [string ]$_.name
168- $displayName = [string ]$_.properties.displayName
169- $scope = [string ]$_.properties.scope
170- ($name -match ' ^[a-f0-9]{24}$' ) -and [string ]::IsNullOrEmpty($displayName ) -and ($scope -match ' /products/.+$' )
171- })
172-
173- if ($candidates.Count -eq 0 ) {
174- Write-Host " No auto-created subscriptions found in ${ScopeLabel} "
175- return
176- }
177-
178- foreach ($candidate in $candidates ) {
179- $subName = [string ]$candidate.name
180- $uri = " https://management.azure.com/subscriptions/$SubscriptionId /resourceGroups/$ResourceGroup /providers/Microsoft.ApiManagement/service/$ServiceName /subscriptions/$subName ?api-version=2025-09-01-preview"
181- $null = Invoke-MaskedAzCommand - Replacements @ {
182- $SubscriptionId = Protect-SubscriptionId - Value $SubscriptionId
183- $ResourceGroup = Protect-ResourceGroupName - Value $ResourceGroup
184- $ServiceName = Protect-ApimName - Value $ServiceName
185- } - Arguments @ (' rest' , ' --method' , ' delete' , ' --url' , $uri )
186-
187- if ($LASTEXITCODE -eq 0 ) {
188- Write-Host " Deleted subscription: $subName "
189- } else {
190- Write-Host " ⚠️ Failed to delete subscription: $subName "
191- }
192- }
193- }
194-
195138function Invoke-Teardown {
196139 if ($SkipTeardown ) {
197140 Write-Host " ⏭️ Teardown skipped (-SkipTeardown)"
@@ -544,8 +487,6 @@ try {
544487 Write-Host " Source: $ ( Protect-ApimName - Value $sourceName ) (sub: $ ( Protect-SubscriptionId - Value $sourceSubId ) , rg: $ ( Protect-ResourceGroupName - Value $sourceRg ) )"
545488 Write-Host " Output: $ExtractOutputDir "
546489
547- Remove-KnownAutoSubscriptions - SubscriptionId $sourceSubId - ResourceGroup $sourceRg - ServiceName $sourceName - ScopeLabel ' source'
548-
549490 $apiopsLogLevel = Get-ApiopsLogLevel - ScriptLogLevel $LogLevel
550491
551492 # For SKUs that support workspaces (Premium / PremiumV2), pass a filter file
@@ -689,8 +630,6 @@ loggers:
689630 Write-Host " Target: $ ( Protect-ApimName - Value $targetName ) (sub: $ ( Protect-SubscriptionId - Value $targetSubId ) , rg: $ ( Protect-ResourceGroupName - Value $targetRg ) )"
690631 Write-Host " Input: $ExtractOutputDir "
691632
692- Remove-KnownAutoSubscriptions - SubscriptionId $targetSubId - ResourceGroup $targetRg - ServiceName $targetName - ScopeLabel ' target'
693-
694633 $publishExitCode = Invoke-MaskedApiopsCommand - Replacements @ {
695634 $targetSubId = Protect-SubscriptionId - Value $targetSubId
696635 $targetRg = Protect-ResourceGroupName - Value $targetRg
0 commit comments