Creating a Script Using Cmdlets
The following procedure uses a Windows PowerShell file (.ps1) file.
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) file.
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% environment variable:
If ($env:ZertoOperation -eq "FailoverBeforeCommit" -or "MoveBeforeCommit") { desired code here } else { alternative code here } |
4. Update VPG definitions that you want to run the 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>, for example, C:\ZertoScripts\yourscript.ps1.
Note: You might have to set the remote signed execution policy. For example, using the following:
##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: It is recommended to test a PowerShell script by running it from the command line, to ensure it runs correctly.
For full details about recovery scripts, refer to the Zerto Virtual Manager Administration Guide.