Last active
July 14, 2021 08:07
-
-
Save jhoneill/ef998395cea64396d3808693f6e789e2 to your computer and use it in GitHub Desktop.
Re-deploying the API management service fails and help says call the REST API: here's a script to do it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.synopsis | |
Remove Soft-deleted API Management service | |
.description | |
Re-deploying the API management service fails with a message | |
See https://aka.ms/apimsoftdelete | |
That says call the REST API. This does that. | |
#> | |
[cmdletbinding(SupportsShouldProcess=$true,confirmImpact='High' )] | |
param ( | |
#Specify name of APIManagementService | |
$name = "*" | |
) | |
$subscriptionid = (Get-AzContext).Subscription.id | |
$authresp = Get-AzAccessToken -ResourceUrl $managmentUrl | |
$headers = @{Authorization = "Bearer $($authresp.Token)"} | |
$uri = "$managmentUrl/subscriptions/$subscriptionid/providers/Microsoft.ApiManagement/deletedservices" | |
Invoke-RestMethod -Headers $headers -Uri ($uri + "?api-version=2020-06-01-preview") | Select-Object -ExpandProperty value | | |
Where-Object -Property name -Like $name | ForEach-Object { | |
if ($PSCmdlet.ShouldProcess($_.name , 'Remove soft-deleted ApiManagement Service')) { | |
$u2 = "$managmentUrl" + $_.id + "?api-version=2020-06-01-preview" | |
Invoke-RestMethod -Uri $u2 -Headers $headers -Verbose -Method delete | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment