VMware Cloud Community
kriskearley
Contributor
Contributor

SRM PowerCLI Scripting: Add Test Network Mapping to Recovery Plan

I'm using SRM 8.1 with vCenter 6.5 and i'm trying to script out the mapping of the test network for recovery plans and i'm having issues with getting the correct moref for the recovery network to create the mapping.

I'm using PowerCLI 6.5 with Ben Meadowcrofts srm cmdlets.

Here is my script:

import-module C:\Windows\System32\WindowsPowerShell\v1.0\Modules\SRM-Cmdlets\Meadowcroft.Srm.psd1

$cred = get-credential

connect-viserver vc-protected.domain.local -Credential $cred | out-null

connect-viserver vc-recovery.domain.local -Credential $cred | out-null

connect-srmserver -remotecredential $cred -credential $cred

$recovplans = Get-SrmRecoveryPlan -name "TEST-PLAN"

$networks=get-virtualportgroup -server vc-recovery.domain.local | select name -unique

Foreach($recovplan in $recovplans){

Foreach($network in $networks){

$morefs=Get-View -ViewType network -Filter @{"Name" = $network.Name} | select moref

$morefs=$morefs.moref

Foreach($moref in $morefs){

$recovplan.addtestnetworkmappingtorecoveryplan($moref,$moref)

}

}

}

In the script i'm trying to map the test network to be the same as the recovery network for all networks in a recovery plan.  I thought that i would get the moref of the networks that exist in my recovery site but when i attempted that i got the below error:

Exception calling "AddTestNetworkMappingToRecoveryPlan" with "2" argument(s): "Recovery site network does not exist."

At line:7 char:4

+             $recovplan.addtestnetworkmappingtorecoveryplan($moref,$mo ...

+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : VimException

Any ideas on how i can get the correct moref for the recovery network?

Reply
0 Kudos
1 Reply
klabiak
Enthusiast
Enthusiast

Try to

$morefs=Get-View -ViewType network -Filter @{"Name" = $network.Name} | select -expandproperty moref

and use this as arguments for AddTestNetworkMappingToRecoveryPlan.

Let me know if it help.

Reg.

Reply
0 Kudos