vSphere Replication with PowerCLI - First Look

Using PowerShell and PowerCLI to manage vSphere Replication. A first glance at the new module included in PowerCLI 13.1.

A long-requested feature for vSphere Replication has been the ability to manage it from code, using VMware’s PowerShell Module “PowerCLI”. Management of the (paid-for) Site Recovery Manager (SRM) product has been available for some time, but it’s been lacking for the (free with vSphere) baby sibling vSphere Replication (VR).

PowerCLI 13.1 has implemented a wrapper for recent updates to the VR API, so this functionality is now available and I’ve made a start in finding out how to get this up and running.

Step 1- Install or Update your PowerCLI

If you need it there’s full documentation on docs.vmware.com, but the basics are:

1Update-Module VMware.PowerCLI

We can now have a quick look at the commands we have to play with

1Get-Command -module VMware.Sdk.Vr

Step 2- Connect to the vReplication server

In the same way that regular vCenter work with PowerCLI needs Connect-VIServer to authenticate, we can use Connect-VrServer

1#Connect to the vSphere Replication Server
2Connect-VrServer -Server MyVRServer.example.com

There’s a couple more ID values we need to collect. To keep it simple, this environment has one vCenter and one vReplication server so we have one replication pairing.

1#Get the ID of the pairing on our vCenter
2$PairingID=((Invoke-VrGetVrPairings).List | `
3    Where {$_.LocalVcServer.Name -eq "MyVCenter.example.com"}).PairingId.GUID
4#Get the ID of vCenter 
5$VCGuid=(Invoke-VrGetVrInfo).VCGuid.guid

Step 3- List Replications

Now we’re all connected, we can start using the cmdlets in anger. As these are new, and we’re just starting out, let’s have a look at retrieving some data on the replications in our environments.

1#Count the number of Replications configured
2Invoke-VrGetReplicationsCount -pairingId $pairingID
3#Get all the configured replications
4(Invoke-VrGetAllReplications -pairingId $pairingID -SourceVcGuid $VCGuid -ExtendedInfo $true).List
5#Make a table with a list of VMs and their current replication status
6(Invoke-VrGetAllReplications -pairingId $pairingID -SourceVcGuid $VCGuid -ExtendedInfo $true).List | `
7Select Name, @{N="status";E={$_.status.status}}, @{N="RpoViolation";E={$_.status.rpoviolation}},RPO

There’s a lot more that can be done here, configuring, managing, and monitoring a vSphere Replication environment, but hopefully this is helpful in getting started. Further examples can be found in the API documentation on developer.vmware.com- PowerCLI snippets are included at the end of the pages.