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.
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.
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.
I recommend that you download the API developer’s guide for SRM as it will help you when working with the PowerCLI module.
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.
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
- 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:
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.
- 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
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.
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.
Stay tuned for the next part that will show you how to find your way around the SRM module and Powershell objects in general.