Press "Enter" to skip to content

Adding Zerto cmdlets to a script

Joshua Stenhouse 1

In order to run Zerto cmdlets inside a script you have to add the snapin. This is easily done with the following command:

add-pssnapin Zerto.PS.Commands

My preferred method of doing this ensures that the script checks it is installed first. You should therefore put this at the start of any script calling Zerto or VMware cmdlets:

function LoadSnapin{

  param($PSSnapinName)

  if (!(Get-PSSnapin | where {$_.Name -eq $PSSnapinName})){

    Add-pssnapin -name $PSSnapinName}}

LoadSnapin -PSSnapinName   "VMware.VimAutomation.Core"

LoadSnapin -PSSnapinName   "Zerto.PS.Commands"

Once you have added the Zerto snapin you can list all of the cmdlets available by entering:

Get-Command | Where-Object{$_.PSSnapin.Name -eq "Zerto.PS.Commands"}

The cmdlets currently available are:

image

For a description on what each cmdlet does and the correct syntax use:

get-help clone-vpg

Happy scripting,

Joshua

  1. Tom Tom

    I created these lines in a recent script that installs the cmdlets MSI then adds the hash for the password (In my case it is passed as a command line variable since this is for an unattended. It should work with a secure string as well.)

    #——————————————————————————#
    # Create Hash file for CMDLET password file. (See Zerto Cmdlets install guide for details.)
    #——————————————————————————#

    $sha1 = [System.Security.Cryptography.SHA1]::Create()
    $bytes = [byte[]][char[]]”$Zertopassword”
    $encryptedBytes = $sha1.ComputeHash($bytes)
    $encryptedBytes | foreach -Begin{$ZertoPassHash=”} -Process{$ZertoPassHash += “{0:x2}” -f
    $_}

    #Write-host $ZertoPassHash
    Add-Content ‘C:\Program Files\Zerto\Zerto Virtual Replication\users.txt’ “`r`n$ZertoUser`t$ZertoPassHash”

Leave a Reply

%d bloggers like this: