diff --git a/eng/common/scripts/Helpers/Resource-Helpers.ps1 b/eng/common/scripts/Helpers/Resource-Helpers.ps1 index 3958a880778..cbeee3bc65c 100644 --- a/eng/common/scripts/Helpers/Resource-Helpers.ps1 +++ b/eng/common/scripts/Helpers/Resource-Helpers.ps1 @@ -75,15 +75,23 @@ function Get-PurgeableResources { Write-Verbose "Retrieving deleted Key Vaults from subscription $subscriptionId" - # Get deleted Key Vaults for the current subscription. - $deletedKeyVaults = @(Get-AzKeyVault -InRemovedState ` - | Add-Member -MemberType NoteProperty -Name AzsdkResourceType -Value 'Key Vault' -PassThru ` - | Add-Member -MemberType AliasProperty -Name AzsdkName -Value VaultName -PassThru) + # TODO: Remove try/catch handler for Get-AzKeyVault - https://github.com/Azure/azure-sdk-tools/issues/5315 + # This is a temporary workaround since Az module >= 9.2.0 uses a more recent API + # version than is supported in the dogfood cloud environment: + # + # | The resource type 'deletedVaults' could not be found in the namespace 'Microsoft.KeyVault' for api version '2022-07-01'. The supported api-versions are + # | '2016-10-01,2018-02-14-preview,2018-02-14,2019-09-01,2021-04-01-preview,2021-06-01-preview,2021-10-01,2021-11-01-preview'. + try { + # Get deleted Key Vaults for the current subscription. + $deletedKeyVaults = @(Get-AzKeyVault -InRemovedState ` + | Add-Member -MemberType NoteProperty -Name AzsdkResourceType -Value 'Key Vault' -PassThru ` + | Add-Member -MemberType AliasProperty -Name AzsdkName -Value VaultName -PassThru) - if ($deletedKeyVaults) { - Write-Verbose "Found $($deletedKeyVaults.Count) deleted Key Vaults to potentially purge." - $purgeableResources += $deletedKeyVaults - } + if ($deletedKeyVaults) { + Write-Verbose "Found $($deletedKeyVaults.Count) deleted Key Vaults to potentially purge." + $purgeableResources += $deletedKeyVaults + } + } catch { } return $purgeableResources }