1

Is there a way to list all the VMS listed in recovery vault using powershell?

I've been hunting around online and have only seen commands to manage virtual machines but not list them. I'm trying to list all the protected VMS and the last backup date. If it's possible.

Thanks in advance :)

  • Hi Jason thanks for your help, I'll give that a go later, could you just give me an idea what a container is in this context and what its role here? Thanks – Norrin Rad Jul 19 '17 at 5:55
  • Hi, based on my knowledge, container same as a folder, we backup Azure VMs to that folder, then different VMs' backup store in different sub-folders. Please let me know if you would like further assistance. – Jason Ye Jul 19 '17 at 8:29
  • Hi Jason I'm getting the error cannot convert 'system object []' to type Microsoft.azure.commands.recoveryservices.backup.cmdlets.models.containerbase .. however when I do a $nameContainer it shows all VMS and state but not the last backup date – Norrin Rad Jul 19 '17 at 8:30
  • Please try to add -FriendlyName "vmname", and try angain – Jason Ye Jul 19 '17 at 8:31
  • @JasonYe-MSFT excellent thanks Jason. I tried your code on my home subscription and it works a treat .. thanks 👍 – Norrin Rad Jul 19 '17 at 12:08
3

I'm trying to list all the protected VMS and the last backup date

We can use PowerShell to list VMs in the recovery service vault and the latest recovery point, like this:

Get-AzureRmRecoveryServicesVault -Name "jasonbackup" -ResourceGroupName "backup" | Set-AzureRmRecoveryServicesVaultContext

$nameContainer = Get-AzureRmRecoveryServicesBackupContainer -ContainerType "AzureVM" -Status "Registered" -FriendlyName "jasonvm"

Get-AzureRmRecoveryServicesBackupItem -Container $nameContainer -WorkloadType "AzureVM" | select ContainerName,LatestRecoveryPoint

enter image description here

My VMs name are jasonvm and jasonvm2.

=============================================
Update:

If we have many VMs, we can use Foreach to list Azure VM Name and LatestRecoveryPoint, we can use this script:

Get-AzureRmRecoveryServicesVault -Name "jasonbackup" -ResourceGroupName "backup" | Set-AzureRmRecoveryServicesVaultContext

$fnames = Get-AzureRmRecoveryServicesBackupContainer -ContainerType "AzureVM" -Status "Registered" | select  -ExpandProperty friendlyname

 foreach ($name in $fnames)
 {
 $nameContainer = Get-AzureRmRecoveryServicesBackupContainer -ContainerType "AzureVM" -Status "Registered" -FriendlyName $name
 Get-AzureRmRecoveryServicesBackupItem -Container $nameContainer -WorkloadType "AzureVM" | select ContainerName,LatestRecoveryPoint
 }

enter image description here enter image description here

| improve this answer | |
  • Perfect .. worked a treat .. thank you for your help. :) – Norrin Rad Jul 20 '17 at 10:21
  • Saved me from a restless weekend pulling my hair out, great help thank you 👍👍 – Norrin Rad Jul 20 '17 at 10:23
0

I'm having trouble with the Set-AzureRmRecoveryServicesVaultContext command (Powershell 6.0 with AZ Module). it seems it will be deprecated to set the context as suggested here: KB MS

just add the -vaultID value to the Jason's command, eg:

$vaultID = Get-AzRecoveryServicesVault -ResourceGroupName "backup" -Name "jasonbackup" | select -ExpandProperty ID
fnames = Get-AzRecoveryServicesBackupContainer -ContainerType "AzureVM" -Status "Registered" -VaultId $vaultID | select  -ExpandProperty friendlyname
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.