mRhNs13
mRhNs13

Reputation: 479

cannot remove azure subscription

I have used this command Remove-AzureSubscription "XXX" to remove the subscription. When I use the Get-AzureSubscrition command again It display the subscription which I have deleted. How to resolve this issue and remove the subscription completely using power shell.

Upvotes: 2

Views: 1338

Answers (1)

MikeWo
MikeWo

Reputation: 10985

Get-AzureSubscription currently always goes out to the Azure API to return the list of subscriptions related to the account credentials for the session. The Remove-AzureSubscription does work to remove the subscription from the list of "known" subscriptions locally, but if you perform a Get-AzureSubscription again the list of subscriptions gets refreshed.

You can see this if you perform a Get-AzureSubscription, followed by a Remove-AzureSubscription and then try to set the current subscription to the one you just removed using Select-AzureSubscription. That cmdlet will fail stating, "Select-AzureSubscription : The subscription name someSub doesn't exist."

The Remove-Subscription help is explicit when it states, "The Remove-AzureSubscription cmdlet deletes an Azure subscription from your subscription data file so Windows PowerShell can't find it. This cmdlet does not delete the subscription from Microsoft Azure, or change the actual subscription in any way." The Get-AzureSubscription cmdlet actually updates the datafile back to include all subscriptions.

If you are looking for a way to get a list of subscriptions to then iterate through while excluding some of them you will need to set up that list differently than just calling Get-AzureSubscription each time you need it. Another option is you can report an Issue on GitHub for the Azure cmdlets to request a parameter for Get-AzureSubscription which would only return the ones in the data file locally without refreshing it.

Update: it occurred to me that you may be asking how to delete a subscription completely using PowerShell. There is not currently a way to do that. If you need to cancel a subscription you do that via the account site. You log in and select the Subscriptions tab. Then select the subscription and on the right hand side there is a cancel subscription. This is how you cancel a subscription and it must be done by the Service Administrator. Note that this may not remove the subscription from your PowerShell Get-AzureSubscription calls immediately. The cancelled subscription may hang around a while.

Upvotes: 2

Related Questions