azure-powershell icon indicating copy to clipboard operation
azure-powershell copied to clipboard

Get-AzureRmResourceGroup and Remove-AzureRmResourceGroup throws ArgumentException if resource does not exisit

Open hovsepm opened this issue 10 years ago • 6 comments

Repro:

Get-AzureRmResourceGroup –Name 'CdvKeyVaultResourceGroup' –Location 'West US'
Get-AzureRmResourceGroup : Provided resource group does not exist.
At line:1 char:1
+ get-AzureRmResourceGroup –Name 'CdvKeyVaultResourceGroup' –Location ' ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Get-AzureRmResourceGroup], ArgumentException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Resources.GetAzureResourceGroupCommand

Expected: Get[/Remove]-AzureRmResourceGroup should return an empty result if resource group does not exist.

hovsepm avatar Feb 05 '16 19:02 hovsepm

Lets fix this.

ravbhatnagar avatar Feb 11 '16 22:02 ravbhatnagar

@TianoMS - Can you please take a look?

ravbhatnagar avatar May 24 '16 00:05 ravbhatnagar

@hovsepm I checked the other cmdlets on how to handle similar cases, and the practice seems to be throwing exception.

Get-Process -Id 1234, throws ObjectNotFound exception. Get-AzureRmSubscription -Id "non-existing-Id", throws PSArgumentException.

I think I'll resolve this one as won't fix.

TianoMS avatar May 28 '16 00:05 TianoMS

@TianoMS we should fix it in the other places as well. PSArgumentException/ArgumentException is wrong.

hovsepm avatar Jun 07 '16 05:06 hovsepm

Fixed in 1.6.0

ravbhatnagar avatar Jul 14 '16 18:07 ravbhatnagar

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @rthorn17

ghost avatar Aug 14 '19 19:08 ghost