Managing VPGs : Running Scripts Before or After Recovering a VPG : Example Scripts
  
Example Scripts
IMPORTANT: The scripts are provided by example only and are not supported under any Zerto support program or service.
The following scripts are examples of how to provide scripts to use with Zerto Virtual Replication:
Example 1 – Recording Failover Tests.
Example 2 – Moving Virtual Machines to a Resource Pool After a Failover.
Example 1 – Recording Failover Tests
The following script, c:\ZertoScripts\TestedVPGs.bat, writes the VPG name and date to the ListOfTestedVPGs.txt file every time a failover test is run:
SET isodt=%date:~10,4%-%date:~7,2%-%date:~4,2% %time:~0,2%-%time:~3,2%-%time:~6,2%
IF %1==Test ECHO %2 %isodt% >> c:\ZertoScripts\Results\TestedVPGs.txt
Where %1 is the first parameter in the list of parameters, %ZertoOperation%, and %2 is the second parameter in the list of parameters, %ZertoVPGName%.
Note: If the file TestedVPGs.txt does not exist it is created, as long as the folder, c:\ZertoScripts\Results, exists.
 
Example 2 – Moving Virtual Machines to a Resource Pool After a Failover
The following PowerShell script is an example of how to move virtual machines into resource pools as a post-recovery script. This script could be used when you want to move virtual machines into a resource pool following a failover and want to designate the resource pool only at the time of the failover and not as part of the VPG definition. Note that this script is a basic example and requires some configuration, as noted in the comments of the script:
##The following are a list of requirements for this script:
##    - This script must be present in the same directory on both sites listed in
##      the Manage VPGs dialog
##    - PowerShell v2.0 installed on both Zerto Virtual Managers
##    - VMWare PowerCLI installed on both Zerto Virtual Managers
##
##This script was written by Zerto Support and is used at the customer's own risk
## and discretion.
##
##Note: The desired resource pool MUST exist on the hypervisor manager prior to
##running this script.
##
##To run this script from the VPG screen, an example command is 'powershell.exe'
##with the parameter 'C:\ZertoScripts\Move-VMs.ps1'
##
##START OF SCRIPT
##
##PowerCLI requires remote signed execution policy - if this is not enabled,
##it may be enabled here by uncommenting the line below.
 
##Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force
 
##Below are the variables that must be configured.
##Variables:
 
##The location of this script
$strMoveScriptLoc = "C:\Zerto Scripts\"
 
##vCenter IP address
$strVCenterIP = "10.10.10.10"
 
##vCenter user account to use; account must have ability to move desired machines
$strVCUser = "Administrator"
##vcenter user password
$strVCPw = "password"
 
##Name of resource pool in vCenter
$strResPool = "ResourcePool"
 
##Array of VMs to move; it includes ALL VMs in the VPG and is case sensitive.
$strVMtoMove = @("VM-1", "VM-2", "VM-3")
 
##The PowerCLI snap-in must first be registered
Add-PSSnapin VMware.VimAutomation.Core
 
##Move to directory where script is located
CD $strMoveScriptLoc
 
##Connect to target VC server based on variables above
Connect-VIServer -Server $strVCenterIP -Protocol https -User $strVCUser -Password $strVCPw
 
##execute the move for each VM specified
foreach ($objVM in $strVMtoMove){
  Move-VM -VM $objVM -Destination $strResPool }
 
##Disconnect from session with VC server
Disconnect-VIServer -Server $strVCenterIP -Force
 
##End of script