Reader small image

You're reading from  Learning PowerCLI - Second Edition

Product typeBook
Published inFeb 2017
Publisher
ISBN-139781786468017
Edition2nd Edition
Right arrow
Author (1)
Robert van den Nieuwendijk
Robert van den Nieuwendijk
author image
Robert van den Nieuwendijk

Robert van den Nieuwendijk is an IT veteran from the Netherlands with over thirty years of experience in Information Technology. He holds a bachelor degree in software engineering. After working a few years as a programmer of air traffic control and vessel traffic management systems, he started his own company Van den Nieuwendijk Informatica in 1988. Since then he has worked as a freelance systems administrator of OpenVMS, Windows Server, Linux, and VMware vSphere systems, for Dutch governmental organizations and cloud providers. During winter he is also a ski and snowboard instructor at an indoor ski school. With his background as a programmer, he always tries to make his job easier by writing programs or scripts to perform repeating tasks. In the past, he used the C programming language, OpenVMS DCL, Visual Basic Script and KiXtart to do this. Now, he uses Microsoft PowerShell and VMware PowerCLI for all of his scripting work. Robert is a frequent contributor and moderator at the VMware VMTN Communities. Since 2012 VMware awarded him the vExpert title for his significant contributions to the community and a willingness to share his expertise with others. He has a blog at http://rvdnieuwendijk.com where he writes mainly about VMware PowerCLI, Microsoft PowerShell, and VMware vSphere. If you want to get in touch with Robert, then you can find him on Twitter. His username is @rvdnieuwendijk. Robert is also the author of Learning PowerCLI, Packt Publishing.
Read more about Robert van den Nieuwendijk

Right arrow

Chapter 12.  Using Site Recovery Manager

VMware Site Recovery Manager is VMware's product for disaster recovery. With Site Recovery Manager (SRM), you can create recovery plans to migrate or failover virtual machines from protected sites to recovery sites. Virtual machines can be copied from protected sites to recovery sites using array-based replication or host-based replication.

The coverage in PowerCLI for SRM is limited. There are only two cmdlets in PowerCLI for SRM: Connect-SrmServer and Disconnect-SrmServer. After connecting to an SRM server, you have to use the SRM API to manage SRM. Fortunately, Ben Meadowcroft, a former VMware SRM product manager, has created a PowerShell module containing advanced functions to work with SRM via PowerCLI. The module is named Meadowcroft.SRM.

In this chapter, you will learn to use the Meadowcroft.SRM module and the SRM API to manage SRM.

This chapter covers the following topics:

  • Installing SRM

  • Connecting to SRMservers

  • Downloading and installing the Meadowcroft...

Installing SRM


SRM will be used to create recovery plans to migrate or failover virtual machines from protected sites to recovery sites. Because you want your virtual environment to run at the recovery site in the case your protected site is unavailable, both sites need a vCenter Server and an SRM server. The SRM application must be installed on a Windows Server computer. For supported Windows Server versions, you should check the VMware Compatibility Guide. You can find the VMware Compatibility Guide for SRM at http://www.vmware.com/resources/compatibility/search.php?deviceCategory=sra .

Virtual machines that you want to protect using SRM have to be replicated from the protected site to the recovery site. There are two ways to replicate the virtual machines:

  • Array-based replication

  • Host-based replication

For array-based replication, you have to configure the replication of virtual machines from the protected site to the recovery site on your storage array.

If you don't have an array that supports...

Connecting to SRM servers


Before you can manage SRM from PowerCLI, you have to connect to the SRM servers you want to manage. Because SRM fails over virtual machines from a protected site to a recovery site, both sites need a vCenter Server and an SRM server. So, if you want to manage both SRM servers, you will have to connect to each of them. After connecting to an SRM server, you can use the ExtensionData property of the output of the Connect-SrmServer cmdlet to access the SRM API.

The Connect-SrmServer cmdlet establishes a connection to an SRM server. The syntax of the Connect-SrmServer cmdlet is given here. The first parameter set is the default. You can use this parameter set if you have a connection to a vCenter Server that has an SRM server associated with it:

Connect-SrmServer [-User <String>] [-Password <SecureString>]
    [-Port <Int32>] [-Protocol <String>] [-Credential <PSCredential>]
    [-RemoteCredential <PSCredential>] [-RemoteUser <String...

Downloading and installing the Meadowcroft.SRM module


In this section, you will learn how to download and install the PowerShell module created by Ben Meadowcroft to manage SRM via PowerCLI. You can download this module from http://www.benmeadowcroft.com/projects/srm-cmdlets-for-powercli/ . After opening the web page, you have to click on SRM-Cmdlets.zip to download the module.

After downloading the SRM-Cmdlets.zip file, unblock the file with the PowerShell Unblock-File cmdlet, using the following command:

PowerCLI C:\> Unblock-File -Path SRM-Cmdlets.zip

The preceding command does not return any output.

To import a module in your PowerSell session, you have to install the module in a folder in your PowerShell module path. The environment variable PSModulePath contains a list of folders where PowerShell will look for modules. You can inspect the value of the PSModulePath environment variable using the following PowerShell command:

PowerCLI C:\> $env:PSModulePath

On my PC, the preceding...

Pairing SRM sites


In SRM, you have to make a connection between the protected site and the recovery site. This process is named pairing. Unfortunately, pairing SRM sites cannot be done using the SRM API. You have to use the vSphere Web Client to pair the protected site and the recovery site. In the vSphere Web Client, you have to do the following to pair two SRM sites:

Select Home | select Site Recovery under Inventories | expand Sites | select Sites | select the site you want to pair | expand Actions | select Pair Site | type the address of the Platform Services Controller (PSC) in the PSC address field | keep 443 for the port number | click on Next | provide the Single Sign On (SSO) administrative credentials required to perform administrative operations in the PSC in the Username and Password fields | click on Finish.

If the pairing succeeds, you will see two sites in the vSphere Web Client under Site Recovery | Sites. The following screenshot of the vSphere Web Client shows the two SRM...

Retrieving the SRM user info


During installation, SRM creates user accounts at the protected site and the recovery site. You can retrieve the user account of the local site using the GetSolutionUserInfo() method, as shown in the following example. The Format-List cmdlet displays the output in a list view:

PowerCLI C:\> $srmApi.GetSolutionUserInfo() | Format-List

The output of the preceding command is as follows:

SiteUuid : b0fba581-dab6-4e92-add6-6a59589059f9
UserName : SRM-b0fba581-dab6-4e92-add6-6a59589059f9 

In the output of the preceding example, SiteUuid identifies the SRM server. UserName is the name of the SRM user.

The following example shows you the use of the GetPairedSiteSolutionUserInfo() method to retrieve the user account of the paired SRM site:

PowerCLI C:\> $srmApi.GetPairedSiteSolutionUserInfo() | Format-List

The preceding command has the following output:

SiteUuid : 1977d562-cd6c-476f-b467-7d4169a1fe8d
UserName : SRM-remote-b0fba581-dab6-4e92-add6-6a59589059f9

Managing protection groups


SRM protection groups are groups of virtual machines that SRM protects together. One or more protection groups can be included in a recovery plan. Recovery plans will be discussed in more detail in the section Managing recovery plans in this chapter.

There are three types of protection groups:

  • Array-based replication protection groups

  • vSphere replication protection groups

  • Storage policy protection groups

You cannot combine virtual machines replicated by array-based replication and vSphere replication in the same protection group. You cannot protect virtual machines with SRM for which you did not configure array-based or vSphere replication.

The Protection property of the $SrmApi variable contains methods to create and retrieve protection groups. By piping the output of the $SrmApi.Protection property to the Get-Member cmdlet, we will get a list of the available methods, as shown in the following example.

PowerCLI C:\> $srmApi.Protection | Get-Member

The preceding...

Protecting virtual machines


The Protect-SrmVm function of the Meadowcroft.SRM module will protect a virtual machine and put the virtual machine in an SRM protection group. The syntax of the Protect-SrmVm function is as follows:

Protect-SrmVM [-ProtectionGroup] <SrmProtectionGroup> 
    [[-Vm] <VirtualMachineImpl>] [[-VmView] <VirtualMachine>]  
    [<CommonParameters>]

The -ProtectionGroup parameter is required.

In the following example, we will add virtual machine VM1 to the protection group Protected VMs Protection Group. First, we will retrieve the Protected VMs Protection Group and save it in the variable $SrmProtectionGroup:

PowerCLI C:\> $SrmProtectionGroup = Get-SrmProtectionGroup
    -Name 'Protected VMs Protection Group'

Next, we will retrieve the view of virtual machine VM1 and save it in variable $VMView:

PowerCLI C:\> $VMView = (Get-VM -Name VM1).ExtensionData

Finally, VM1 is added to the Protected VMs Protection Group with the following command...

Retrieving protected virtual machines


You can use the Get-SrmProtectedVM function in the Meadowcroft.SRM module to retrieve the virtual machines protected by SRM. The syntax of the Get-SrmProtectedVM function is as follows:

Get-SrmProtectedVM [[-Name] <String>] [-State {Ready |
    FailedOver | PartiallyRecovered | Recovering | Recovered | 
    Testing | Shadowing}] [-PeerState {Ready | FailedOver | 
    PartiallyRecovered | Recovering | Recovered | Testing | 
    Shadowing}] [-ConfiguredOnly] [-UnconfiguredOnly] 
    [-ProtectionGroup <SrmProtectionGroup[]>] [-RecoveryPlan
    <SrmRecoveryPlan[]>] [-ProtectionGroupName <String>] 
    [-SrmServer <SrmServer>] [<CommonParameters>]

The Get-SrmProtectedVM function has no required parameters. You can use the parameters of the Get-SrmProtectedVM function to filter for specific virtual machines by name, state, configuration, protection group, recovery plan, or SRM server.

In the following example, we will retrieve...

Unprotecting virtual machines


You can remove a virtual machine from a protection group using the Unprotect-SrmVM function in the Meadowcroft.SRM module. The syntax of the Unprotect-SrmVM function is as follows:

Unprotect-SrmVM [-ProtectionGroup] <SrmProtectionGroup> [[-Vm] 
    <VirtualMachineImpl>] [[-VmView] <VirtualMachine>] [[-ProtectedVm] 
    <SrmProtectionGroupProtectedVm>] [<CommonParameters>]

The -ProtectionGroup parameter is required.

In the following example, we will unprotect VM1 and remove it from the Protected VMs Protection Group using the Unprotect-SrmVM function from the Meadowcroft.SRM module, with the following command:

PowerCLI C:\> Unprotect-SrmVM -ProtectionGroup $Srm
    ProtectionGroup -VmView $VmView

The output of the preceding command is as follows:

Key           : dr.replication.VmProtectionGroup.unprotectVms
TaskMoRef     : Task-dr.replication.VmProtectionGroup.unprotectVms59
Description   :
Name          : UnprotectVms
DescriptionId...

Managing recovery plans


Recovery plans are plans that describe the steps to be performed during the execution of a recovery. You can use a recovery plan for a planned migration or a disaster recovery. A recovery plan contains the following information:

  • The name of the recovery plan

  • The location (paired sites) of the recovery plan

  • A protected site

  • The site to which virtual machines in the plan will recover

  • The protection groups to use for the recovery plan

  • The networks to use while running tests of the plan

  • The description of the recovery plan

  • Steps to perform during the execution of the recovery plan

A recovery plan can include one or more protection groups. A protection group can be included in more than one recovery plan.

The steps of the recovery plan can be divided into the following:

  • Test steps

  • Recovery steps

  • Cleanup steps

  • Reprotect steps

In the following sections, Retrieving recovery plans and Running recovery plans, you will learn how to retrieve and run recovery plans. You will also see how to...

Disconnecting from SRM servers


To disconnect your PowerCLI session from one or more SRM servers, you can use the Disconnect-SrmServer cmdlet. The syntax of the Disconnect-SrmServer cmdlet is as follows:

Disconnect-SrmServer [[-Server] <SrmServer[]>] [-Force]
    [-WhatIf] [-Confirm] [<CommonParameters>]

The Disconnect-SrmServer cmdlet has no required parameters.

In the following example, we will disconnect from all of the connected SRM servers:

PowerCLI C:\> Disconnect-SrmServer * -Confirm:$False

The preceding command does not return any output.

Summary


In this chapter, you learned to use SRM from PowerCLI using the Meadowcroft.SRM module and the SRM API. You saw how to install SRM and to connect to SRM servers from your PowerCLI session. We discussed downloading and installing the Meadowcroft.SRM module that provides cmdlets to use SRM. You learned to pair two SRM sites using the vSphere Web Client to make a connection between the protected site and the recovery site. SRM protection groups are groups of virtual machines that SRM protects together. You saw how to manage these protection groups. We discussed protecting virtual machines with SRM and running recovery plans to migrate or fail over virtual machines from the protected site to the recovery site. Finally, you saw how to disconnect your PowerCLI session from SRM servers.

In the following chapter, you will learn how to use VMware vRealize Operations Manager from PowerCLI.

lock icon
The rest of the chapter is locked

Unlock this book and the full library FREE for 7 days

Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
You have been reading a chapter from
Learning PowerCLI - Second Edition
Published in: Feb 2017Publisher: ISBN-13: 9781786468017
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £13.99/month. Cancel anytime

Author (1)

author image
Robert van den Nieuwendijk

Robert van den Nieuwendijk is an IT veteran from the Netherlands with over thirty years of experience in Information Technology. He holds a bachelor degree in software engineering. After working a few years as a programmer of air traffic control and vessel traffic management systems, he started his own company Van den Nieuwendijk Informatica in 1988. Since then he has worked as a freelance systems administrator of OpenVMS, Windows Server, Linux, and VMware vSphere systems, for Dutch governmental organizations and cloud providers. During winter he is also a ski and snowboard instructor at an indoor ski school. With his background as a programmer, he always tries to make his job easier by writing programs or scripts to perform repeating tasks. In the past, he used the C programming language, OpenVMS DCL, Visual Basic Script and KiXtart to do this. Now, he uses Microsoft PowerShell and VMware PowerCLI for all of his scripting work. Robert is a frequent contributor and moderator at the VMware VMTN Communities. Since 2012 VMware awarded him the vExpert title for his significant contributions to the community and a willingness to share his expertise with others. He has a blog at&nbsp;http://rvdnieuwendijk.com where he writes mainly about VMware PowerCLI, Microsoft PowerShell, and VMware vSphere. If you want to get in touch with Robert, then you can find him on Twitter. His username is @rvdnieuwendijk. Robert is also the author of Learning PowerCLI, Packt Publishing.
Read more about Robert van den Nieuwendijk