'Is there a way to find a Removed Keyvault by it's tags
I need to find the KeyVaultname of my removed keyvault (by softdelete) by its specifics tags.
This is the keyvault I need to find:
Unfortunately the command to find the tags for a keyvault by below cmd doesn't work for a Keyvault which is in a Removed state. (It works when the KeyVault is not removed)
(Get-AzKeyvault -InRemovedState -tag @{"RemovalDate" = "14-04-2022"})
Gives the following error:
Get-AzKeyVault : Parameter set cannot be resolved using the specified named parameters.
At line:1 char:2
+ (Get-AzKeyvault -InRemovedState -tag @{"RemovalDate" = "14-04-2022"})
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-AzKeyVault], ParameterBindingException
+ FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.Azure.Commands.KeyVault.GetAzureKeyVault
I tried as well:
(Get-AzKeyvault -InRemovedState | Where-Object {$_.Tag["RemovalDate"] -eq "14-04-2022"})
Which gives the following error:
Cannot index into a null array.
At line:1 char:49
+ ... RemovedState | Where-Object {$_.Tag['RemovalDate'] -eq '14-04-2022'})
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Thank you very much for your help!
Solution 1:[1]
You were close, just needed to pipe results of the Get-AzKeyVault, then query it like any other object.
First, find out the object types that are returned.
Get-AzKeyVault -InRemovedState | get-member
This displays the column names and object type. Now write your query appropriately.
Get-AzKeyVault -InRemovedState |
select VaultName, Tags |
where {$_.Tags["RemovalDate"] -eq "14-04-2022"}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Greg |
