SHIFT

--- Sjoerd Hooft's InFormation Technology ---

User Tools

Site Tools


Sidebar

Recently Changed Pages:

View All Pages


View All Tags


LinkedIn




WIKI Disclaimer: As with most other things on the Internet, the content on this wiki is not supported. It was contributed by me and is published “as is”. It has worked for me, and might work for you.
Also note that any view or statement expressed anywhere on this site are strictly mine and not the opinions or views of my employer.


Pages with comments

View All Comments

srmpowershell

SRM And PowerShell

PowerShell can be a great way to help you create the site recovery you really want. This article talks about installing PowerCLI on a SRM server installed as described here. Also, running the script automatically and adding them into your recovery plan will be discussed.

Installing PowerShell

We have a Site Recovery Server 5.1 server which is installed as described here. To install PowerCLI we first have to install PowerShell, which, on Windows Server 2008 R2 is a feature and can be installed as such:

  • Start Server Manager
  • Click Add Feature
  • Check the “Windows PowerShell Integrated Scripting Environment (ISE)” checkbox and select the .NET Framework dependency
  • Click Next, Install, and Close.

Now we can install PowerCLI. We'll use PowerCLI 5.1 R2, which was released on 2013-02-11 and is released as this executable:

  • VMware-PowerCLI-5.1.0-1012425.exe

Run the executable as an administrator and keep all the defaults during installation.

Also, to speed up PowerCLI go to the control panel → Internet Options → Advanced tab → Security Section → Uncheck the “Check for publisher's certificate revocation” checkbox.

Now, start PowerCLI as an administrator using the shortcuts on the desktop and issue:

Set-ExecutionPolicy RemoteSigned -force
Set-PowerCLIConfiguration -InvalidCertificateAction ignore -ProxyPolicy NoProxy -Confirm:$False
Note: For more information regarding installing, configuring and getting started with PowerShell and PowerCLI see Getting Started with PowerShell and vSphere PowerCLI.


Note: In case you also use 32 bits commands you should also do this in the PowerCLI for 32 bits.

Managing PowerCLI Scripts Authentication

Create a AD service account and grant the account the following permissions:

  • Member of Domain Users
  • Member of the local administrators group
    • Open Server Manager → Configuration → Local Users and Groups –> Groups → Add service account to Administrators group
  • Log on as a service permission
    • Open gpedit.msc → Computer Configuration → Windows Settings → Security Settings → Local Policies → User Rights Assignment → Add service account to “Log on as a service”
  • vCenter permissions
    • Grant the account administrator permissions at the vCenter of the recovery site
Note that the vCenter permissions might be a bit too much. You could just grant permissions at the correct cluster, or use specific roles.

Then configure the SRM service to run under this account:

  • Open services.msc → VMware vCenter Site Recovery Manager Server → Log On → Enter the service account credentials.

Restart the service to make sure the created account works and test your Site Recovery Manager setup.

Adding a PowerCLI Script to a Recovery Plan

Because adding scripts to recovery plans will be a common tasks we put some extra effort in making this look nice. Because adding a powershell script to a recovery plans uses a lot of text in the commands this means it gets quite confusing and unreadable. To prevent this we'll use a redirect command. Create a redirect.cmd in the same location where your scripts will be stored and put the following lines in it:

redirect.cmd:

@echo off
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -psc "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" "& '%1'"

Now you can add a powershell script to a recovery plan like this:

  • Select the recovery plan that should run the script and select the “Recovery Steps” tab.
  • Select the step where you want to run the script before or after and click “Add Step:
  • Now fill in the required settings
  • And click ok.

For reference, the command in the Command Step is this:

c:\windows\system32\cmd.exe /C g:\scripts\redirect.cmd g:\scripts\srmrdms.ps1

Note that without the redirect script you should use this command, and would have to load the VMware snap-ins inside the script:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File g:\scripts\srmrdms.ps1

srmpowershell01.jpg

You have now added an extra step to the recovery plan to run a script, which in this case sets the RDM settings correctly.

You could leave a comment if you were logged in.
srmpowershell.txt · Last modified: 2021/09/24 00:25 (external edit)