I'm writing a Powershell script that queries the status of the latest backup of VMs as follows:
$recoveryVaultInfo = Get-AzRecoveryServicesBackupStatus -Name $vm.Name -ResourceGroupName $vm.ResourceGroupName -Type 'AzureVM'
When I run this piece of the script, I get this error:
Get-AzRecoveryServicesBackupStatus: The client 'XXX' with object id 'XXX' does not have authorization to perform action 'Microsoft.RecoveryServices/locations/backupStatus/action' over scope '/subscriptions/XXX' or the scope is invalid. If access was recently granted, please refresh your credentials.
I am a member of the LogAnalyticsReader group on the BackupVault. I am able to see the status of backups through the Backup Vault > Backup Items blade.
Why can't I do it through Powershell?
Backup reports can be viewed as long as their data is being sent to a Log Analytics workspace. To view reports for a vault or a set of vaults, you need to have reader access to the Log Analytics workspace to which the vault is sending its data. You don't have to have access to the vault.