Following are some examples of Pre-Recovery and/or Post-Recovery scripts for use with Zerto Virtual Replication.


Example 1 – Replace DNS A and PTR Records

The following script, c:ZertoScriptsDNS-Change.ps1, replaces multiple DNS A and PTR records for the two DNS servers, mydns1 and mydns2:



## Set DNS servers

$DNSservers= @("mydns1", "mydns2")

## Filepath to script and CSV files

$FP = "C:ZertoScripts"


Foreach($DNSserver in $DNSservers)


  Import-CSV .DNS-OldA.csv | foreach {

    dnscmd $DNSserver /RecordDelete $ $_.hostname A $_.ip /f}

  Import-CSV .DNS-NewA.csv | foreach {

    dnscmd $DNSserver /RecordAdd $ $_.hostname A $_.ip}

  Import-CSV .DNS-OldPTR.csv | foreach {

    dnscmd $DNSserver /RecordDelete $_.reversezone $_.lowip PTR $_.fqdn /f}

  Import-CSV .DNS-NewPTR.csv | foreach {

    dnscmd $DNSserver /RecordAdd $_.reversezone $_.lowip PTR $_.fqdn}




The script must be in the same folder, C:ZertoScripts, on both the local and remote Zerto Virtual Managers and this is the folder is the folder specified for the variable $FP in the script.

Update Command to run and Params fields for all the VPG definitions that you want to run the script.


Command to run – CMD:powershell.exe

Params – C:ZertoScriptsDNS-Change.ps1

This script requires that the machines running the Zerto Virtual Managers must be logged in as a member of the DNS administrators group and that all prerequisites for DNSCMD.exe are available. In addition, you require the files DNS-OldA.csvDNS-NewA.csvDNS-OldPTR.csv and DNS-NewPTR.csv, with the relevant A and PTR values in the same folder as the PowerShell script (C:ZertoScripts).

This example is for reference only. 

Example 2 – Recording Failover Tests

The following script, c:ZertoScriptsTestedVPGs.bat, writes the VPG name and date to the TestedVPGs.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:ZertoScriptsResultsListOfTestedVPGs.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 ListOfTestedVPGs.txt does not exist it is created, as long as the folder, c:ZertoScriptsResults, exists.

Update Command to run and Params fields for all the VPG definitions that you want to run the script.


Command to run – c:ZertoScriptsTestedVPGs.bat

Params – %ZertoOperation% %ZertoVPGName%

Whenever a failover test is run on the relevant VPGs the TestedVPGs.txt file is updated with the name of the VPG and the date and time the test was run.

Example 3 – 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 would typically be used when you want to move virtual machines into a resource pool following a failover. 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 vCenter Server prior to ##running this script.




##To run this script from the VPG screen, an example command is'powershell.exe' with the parameter 'C:ZertoScriptsMove-VMs.ps1'










##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.








##The location of this script


$strMoveScriptLoc = "C:Zerto Scripts"




##vCenter IP address


$strVCenterIP = ""




##vCenter user account to use; account must have the ability to move thedesired machines


$strVCUser = "Administrator"




##vcenter user password


$strVCPw = "password"




##Name of resource pool in vCenter


$strResPool = "ResourcePool"




##Array of VMs to move - this list should include ALL virtual machines inthe 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