PowerShell Azure Command Get-AzRecoveryServicesVault not returning anything

210 views Asked by At

So I have a PowerShell Script, that works with an Service Principal, and tries to get all Recovery Service Vaults in a specific Subscription. Therefor the Service Principal has the following permission in Azure: 'Microsoft.RecoveryServices/Vaults/read'. The Scope is the Subscription.

When I try to fetch the data from Azure with the following Command I dont get any result: Get-AzRecoveryServicesVault With my Admin Account (Contributor rights), the Script, returns the Recovery Service Vaults. Also, when I use Azure Graph Search-AzGraph -Query "Resources | where type =~ 'Microsoft.RecoveryServices/vaults'"with the Service Principal I get the expected result, only issue seems to be that the Get-AzRecoveryServicesVault doesnt work. Am I missing anything?

1

There are 1 answers

11
Jahnavi On BEST ANSWER

If you receive empty results, it could be because you entered the wrong subscription details or that the subscription you selected did not include any recovery service vaults.

Check below to resolve the issue:

  1. Try clearing the token cache with Clear-AzContext -Force command once you logged into the account using Connect-AzAccount.
  2. Before retrieving the results, set the required subscription ID context with below command.
Set-AzContext -SubscriptionId "xxx"
  1. Also check that the Service Principal have the required vault or resource group level permissions. At the resource group level, where the Recovery Services vault is located, assign the Reader role to the Service Principal and Backup Operator role at the vault level to the Service Principal.

enter image description here

After checking all the above, I tried retrieving the expected results with Get-AzRecoveryServicesVault command and was successful as shown.

enter image description here