Creating a Script
There are many ways to create scripts to run before or after recovering a VPG. The following procedure uses a Windows PowerShell file (.ps1).
To create a script:
1. | Create a file on the machine where the Zerto Virtual Manager that manages the recovery is installed. |
2. | Enter the script that you want to run in the file. |
3. | Save the file as a Windows PowerShell file (.ps1). |
When writing a PowerShell script, you can include the environment variables in the script. For example, the following code snippet shows the use of the %ZertoOperation% and %ZertoVPGName% environment variables:
$Operation = $env:ZertoOperation
$VPG = $env:ZertoVPGName
$time = Get-Date
if ($Operation -eq "Test") {
"$time VPG: $VPG was tested." >> "C:\ZertoScripts\VPG_DR.txt"
}
if ($Operation -eq "FailoverBeforeCommit") {
"$time Failover before commit was performed. VPG: $VPG" >> "C:\ZertoScripts\VPG_DR.txt"
}
if ($Operation -eq "MoveBeforeCommit"){
"$time Move before commit was performed. VPG: $VPG" >> "C:\ZertoScripts\VPG_DR.txt"
}
Pre-recovery scripts must be saved on the protected site Zerto Virtual Manager machine. Post-recovery scripts must be saved on the recovery site Zerto Virtual Manager machine.
Note: | Zerto recommends having both pre- and post-recovery scripts, available on both the protected and recovery Zerto Virtual Manager machines, so that they will work from the protected site and after reverse protection from the recovery site. |
4. | Update Command to run and Params fields for all the VPG definitions that you want to run the script. |
Passing parameters is implemented differently for the two script types. For information about passing command line parameters, refer to the relevant PowerShell or batch file documentation.
Using a PowerShell Script
Windows PowerShell scripts require Windows PowerShell (.exe) to execute. To specify a PowerShell script, update Command to run and Params fields for all the VPG definitions that you want to run the script.
Command to run: powershell.exe
Params: <script_including_path> <Zerto_Params>, for example:
C:\ZertoScripts\PostScript.ps1 %ZertoOperation% %ZertoVPGName%
Use quotes (“) around the path if it includes spaces.
Note: | You might have to set the remote signed execution policy. |
##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
Note: | Zerto recommends testing both PowerShell and batch scripts by running them from the command line, to ensure that they run correctly. |