VMware’s disaster recovery solution is a great way to be prepared for the worst and gives you peace of mind when you know that your workloads are protected on the recovery site. As they say it, a good admin is a lazy admin. And just like you lot out there, there is one thing that I cannot stand is manual repetitive tasks. These things should not happen if you are interested in scripting.

SRM in PowerCLI

Because of this, Site Recovery Manager can become annoying to keep clean over time. Especially if you are using Array-Based Replication (ABR). For example, whenever someone migrates a VM to another datastore that belongs to another protection group, the status of the “source” protection group turns to “Not configured” with the VM in error because it is no longer protected and the “destination” protection group is also “Not configured” with the VM in “Not configured” state. You end up with warnings all over the place not knowing which is an actual error and which needs to be configured.

Of course, this is kind of a first world problem but when you have a fast moving environment and you need to go through all the protection groups one by one to click “configure all”, it quickly becomes really boring.

VMware provides a module for Site Recovery Manager as part of PowerCLI. However, this module is comparable to the Horizon module in the sense that they only provide cmdlets to connect and disconnect the server. Once connected you have to get your hands dirty. Everything is done using methods and properties offered by the exposed API.

Vembu BDR Suite

Backup your Virtual & Physical Machines
Free Forever
Agentless Backups, Flexible Scheduling, Multiple Recovery Options

In this article, I will show you how to get started with this module and I will also throw bonus functions to save some time.

Official documentation

I recommend that you download the API developer’s guide for SRM as it will help you when working with the PowerCLI module.


SRM in PowerCLI

As you can see there is a community module that you could use, however, I find it more interesting to get stuck in the module and learn something in the process.


I recommend that you install the latest version of PowerCLI to be up to date. The current version 11.0.0 of PowerCLI required Powershell version 3.0 or newer.

If you have PowerCLI 6.5R1 or earlier installed you need to uninstall it first.

If your station has access to the internet you can install PowerCLI this way or update if already installed in a version greater 6.5.1.

Install-Module -Name VMware.PowerCLI
Update-Module -Name VMware.PowerCLI

If your station does not have access to the internet you have the possibility to download the PowerCLI modules as a zip file on VMware Code.

  • Go to VMware Code
  • Choose the latest version of PowerCLI
  • Click Download next to the zip file

SRM in PowerCLI

  • Transfer the zip file to your offline management station and unzip the modules in a Module path for Powershell (e.g. %USERPROFILE%\Documents\WindowsPowerShell\Modules).

Check that the module is properly installed by running this command in PowerShell. The output should be as follows:

PS> Get-Module -ListAvailable -Name VMware.VimAutomation.Srm
Directory: C:\Users\xavier\Documents\WindowsPowerShell\Modules

ModuleType Version Name ExportedCommands
Script 10.0.0… VMware.VimAutomation.Srm {Connect-SrmServer, Disconnect-SrmServer}

Connection to Site Recovery Manager

The user account you are going to use to connect to SRM needs to have the rights to interact with it. This is done in the vSphere web client in Administration > Access Control > Global Permissions. If your user has the role ‘Administrator’ applied you don’t need to do anything. However, if you want granular security or if you want a dedicated user for this purpose, you can assign one of the built-in SRM roles.

There are different ways to go on about connecting to SRM in PowerCLI, however, we will stick with the standard way which is also the most efficient one.

  • First, connect to one of the vCenter servers of the SRM pair.

I always connect to the protected site out of habit and because it makes it easier to cross-reference the information later but you are free to connect to the recovery site should you want to.

PS> Connect-VIServer -Server srv-vcenter-A

Name Port User
mg-p-vcntr11 443 MyDomain\xavier
  • Connect to the SRM servers. Note that you don’t need to specify the name of the SRM server as you are already connected to vCenter.

I found that the cmdlet to connect cannot make use of the credentials of the current session like Connect-VIServer does it so you have to type the credentials twice

PS> Connect-SrmServer -Credential (Get-Credential) -RemoteCredential (Get-Credential)

cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:

cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:

ServiceUri : https://srv-srm.mydomain.local:9086/vcdr/extapi/sdk
SessionSecret : “81f0c14d6b1cb72c749c0f15d7ec06e097b29326”
User : xavier
IsConnected : True
Port : 9086
Version : 6.5.1
Build : 8266157
ProductLine : srm
InstanceUuid : 332d0b00-3209-4a32-a7db-10054e2ef7e3
RefCount : 1
ExtensionData : VMware.VimAutomation.Srm.Views.SrmServiceInstance
Uid : /SrmServer=xavier@srv-srm.mydomain.local:9086/
Id : /SrmServer=xavier@srv-srm.mydomain.local:9086/
Name : mg-p-srm11.mgmtdom.intra
IsInUse : True

The output of the cmdlet is the content of the global variable $defaultsrmservers (just like Connect-VIServer and $DefaultVIServer).

Consider the $defaultsrmservers variable as the brain of the SRM module. Every action to interact with SRM will be done using this variable, it will quickly become your best friend.

Bonus Function

Check out my Connect-SRMPair function to quickly connect to the SRM pair (if you can connect to both local and remote site with the same credentials). You can store it in your PowerShell profile or in a homemade module to have it at your disposal in Powershell at any time.

Once you are connected to vCenter, just type Connect-SRMPair and you will be prompted for credentials. The function will then connect to both servers of the SRM pair.

Function Connect-SRMPair {

$Credentials = (Get-Credential $env:username)

Write-host “Connecting to local SRM server..” -ForegroundColor DarkCyan

if (Connect-SrmServer -Credential $Credentials) {
Write-host “Connecting to remote SRM server..” -ForegroundColor DarkCyan



Stay tuned for the next part that will show you how to find your way around the SRM module and Powershell objects in general.

Follow our Twitter and Facebook feeds for new releases, updates, insightful posts and more.

Like what you read? Rate us
SRM in PowerCLI: Part 1 – Introduction
Rate this post