azureazure-site-recovery

Associate Protection Container With Replication Policy - ASR PowerShell - Scripting


I'm trying to Build a Script for automating/simplify the task of implement Azure Site Recovery.

It's being hard since all Microsoft Docs are mostly bad documented, and the cmdlets are mostly obsolete and marked as being deprecated.

Til now I could accomplish the following steps:

-Create the Storage Acc

-Create The Virtual Network

-Create the Resource Group

-Create the Vault and import is FileSettings

-Create The Site

-Install the provider and Agent

-Create the Replication Policy

(All of this by PowerShell, already with the new cmdlets and modules after hard work)

Now I'm Having a few problems to Associate the replication Policy with the Protection Container.

My Cmdlets is the following:

#Associate Protection Container With Replication Policy 
$PolicyRslt=Get-AzureRmRecoveryServicesAsrPolicy -Name $PolicyName
$AssJob=Start-AzureRmSiteRecoveryPolicyAssociationJob -Policy $PolicyRslt -PrimaryProtectionContainer $Container

And I get the error:

Start-AzureRmSiteRecoveryPolicyAssociationJob : Cannot bind parameter 'Policy'. Cannot convert the "Microsoft.Azure.Commands.RecoveryServices.SiteRecovery.ASRPolicy" value of
type "Microsoft.Azure.Commands.RecoveryServices.SiteRecovery.ASRPolicy" to type "Microsoft.Azure.Commands.SiteRecovery.ASRPolicy".
At line:1 char:63
+ ... t-AzureRmSiteRecoveryPolicyAssociationJob -Policy $PolicyRslt -Primar ...
+                                                       ~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Start-AzureRmSi...yAssociationJob], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Azure.Commands.SiteRecovery.StartAzureSiteRecoveryPolicyAssociationJob

Can please anyone help me? I cant get a way to associate the JOB with the recovery services Module, and I cant get the Policy with the Cmdlet Get-AzureRmSiteRecoveryPolicy because already obsolete

Thanks in Advance for everyone!


Solution

  • You cannot mix and match cmdlets from the AzureRm.RecoveryServices.SiteRecovery module and the AzureRm.SiteRecovery module as the PowerShell objects that get created are of different types.

    Stick to using cmdlets from the AzureRm.RecoveryServices.SiteRecovery module and you should be fine. Here is a reference: https://learn.microsoft.com/en-us/powershell/module/AzureRM.RecoveryServices.SiteRecovery/?view=azurermps-5.2.0

    The cmdlet you are looking for is New-AzureRmRecoveryServicesAsrProtectionContainerMapping (aliased to New-AsrProtectionContainerMapping)

    P.S : The AzureRm.SiteRecovery module will be deprecated at a future date