I have set up Azure Site Recovery from Vmware to Azure. I have an ASR appliance in Vmware. I am trying to automate failovers and failback with powershell.
I am able to do test failovers and cleanups. The full failover is a bit more challenging. There are more steps.
FAILOVER - failover, commit, re-protect (RecoveryToPrimary).
FAILBACK - PlannedFailover, Commit, re-protect (oPrimaryToRecoveryT).
I am stuck on the re-protect steps. here is my code.
#Variables
$VaultName = "rsv-myvault"
$ASRRecoveryPlanName = "PLAN-TST-TEST"
$TestFailoverVNetName = "myVnett"
$resourceGroupname = "MyRG"
$ApplianceName = "L1MGMT-ASR01"
$StorageAccountId = "mystore9cc4"
$Datastorename = "L1DS-SRV02"
$vmname = "myVM"
#Connect
Connect-AzAccount
$subID = (Get-AzSubscription).id
Set-AzContext -SubscriptionId $subID
$vault = Get-AzRecoveryServicesVault -Name $VaultName -ResourceGroupName $resourceGroupName
Set-AzRecoveryServicesAsrVaultContext -Vault $vault
#Network, fabric, container, replicatedItem
$TFOVnet = Get-AzVirtualNetwork -Name $TestFailoverVNetName
$TFONetwork = $TFOVnet.Id
$asrfabric = Get-AzRecoveryServicesAsrFabric
$PrimaryProtContainer = Get-AzRecoveryServicesAsrProtectionContainer -Fabric $asrfabric
$rpi = Get-AzRecoveryServicesAsrReplicationProtectedItem -ProtectionContainer $PrimaryProtContainer -friendlyName $vmname
#FAILOVER:
$TFOJobUnPlan = Start-AzRecoveryServicesAsrUnplannedFailoverJob -ReplicationProtectedItem $rpi -Direction PrimaryToRecovery -Confirm:$false
#COMMIT
$commitJob = Start-AzRecoveryServicesAsrCommitFailoverJob -ReplicationProtectedItem $rpi -Confirm:$false
#RE-PROTECT (I got this from https://www.linkedin.com/pulse/re-protect-different-data-store-azure-preview-m-alim-besari/?trk=public_profile_article_view)
$ReverseContainerMappingName = "crashconsistency-failback-containerpairing"
$reverseContainerMappingObject = GetAzRecoveryServicesAsrProtectionContainerMapping -Name $ReverseContainerMappingName `
-ProtectionContainer $protectionContainer
Update-AzRecoveryServicesAsrProtectionDirection -ReplicateAzureToVMware `
-Direction RecoveryToPrimary `
-Fabric $asrfabric `
-ProtectionContainerMapping $reverseContainerMappingObject `
-ReplicationProtectedItem $rpi `
-LogStorageAccountId $StorageAccountId `
-DataStoreName $DatastoreName `
-ApplianceName $ApplianceName`
#ERROR:
Update-AzRecoveryServicesAsrProtectionDirection : Operation failed. ClientRequestId: eb9fa552-74c6-4c8c-9d24-e07f044ef7d6-2024-02-23 22:10:19Z-Ps No appliance found with the name L1MGMT-ASR01.
When I go to the vault and to Site Recovery Infrastructure > For VMware & Physical Servers > ASR Replication Appliances ... I can see my appliance .. "L1MGMT-ASR01 (10.4.10.27)". I have tried "L1MGMT-ASR01 (10.4.10.27)" and "L1MGMT-ASR01)".
I have looked for a command or combination of commands that would give me the appliance as an object, something like:
$appliance = get-asrAppliance
is there a way to get the appliance with powershell? Am I actually doing this correctly?
For the failback steps I have
#PLANNED FAILOVER
Start-AzRecoveryServicesAsrPlannedFailoverJob -ReplicationProtectedItem $newReplicationProtectedItem -Direction RecoveryToPrimary -Confirm:$false
#COMMIT
Start-AzRecoveryServicesAsrCommitFailoverJob -ReplicationProtectedItem $newReplicationProtectedItem -Confirm:$false
#REPROTECT I have nothing yet.
Any help on coding both re-protect steps would be fantastic. Thanks.