[Resolved] Azure Recovery Services Protection Policy association to VM

Forum: Microsoft Azure
Viewing 2 posts - 1 through 2 (of 2 total)
  • #230313
    Profile photo of John Hann
    John Hann
    Participant

    I am trying to get all the VMs in an Azure Recovery Services Vault and the Protection Policy associated with them.

    I can get all the policies, but not which is associated to a given VM.  I took out the policy cmdlet (Get-AzureRmRecoveryServicesBackupProtectionPolicy)
    <pre class=””>

    $Vaults = Get-AzureRmRecoveryServicesVault

    foreach ($Vault in $Vaults)

    {

           $OutFile = “D:\Azure_BackupInventory_” + $Vault.Name + “.csv”

           $Header | Out-file $OutFile -Force

           $VMs = Get-AzureRmRecoveryServicesBackupContainer -ContainerType “AzureVM”

           foreach ($VM in $VMs)

           {

                  $BkUpItem = Get-AzureRmRecoveryServicesBackupItem -Container $VM -WorkloadType AzureVM

                  $RP = Get-AzureRmRecoveryServicesBackupRecoveryPoint -Item $BkUpItem

                  If ($RP.Count -gt 0)

                  {

                         $o = ‘”‘ + $VM.FriendlyName + ‘”,”‘ + $VM.Status + ‘”,”‘ + $RP.Count + ‘”,”‘ + $RP[0].RecoveryPointTime + ‘”‘

                  }

                  else

                  {

                         $o = ‘”‘ + $VM.FriendlyName + ‘”,”‘ + $VM.Status + ‘”,”‘ + $RP.Count + ‘”,”!!FAILED!!”‘

                  }

                  Add-Content $OutFile $o

           }
    }

    #230314
    Profile photo of John Hann
    John Hann
    Participant

    Added Set-AzureRMRecoveryServicesVaultContext -Vault $vault

    before backupcontainer

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.