Automating Registration of PowerPath Licenses using Powershell/PowerCLI
Summary:
EMC documentation is atrocious. Needless to say, their 'auto-registration' capability is poorly named and represented in my opinion. It makes you think, deploy a vApp, copy license file, and you're done. SOOOO NOT the case. So here is my attempt to hopefully help make the license application portion 'automated' using PowerShell and PowerCLI cmdlets.
PreReq:
EMC documentation is atrocious. Needless to say, their 'auto-registration' capability is poorly named and represented in my opinion. It makes you think, deploy a vApp, copy license file, and you're done. SOOOO NOT the case. So here is my attempt to hopefully help make the license application portion 'automated' using PowerShell and PowerCLI cmdlets.
PreReq:
- PowerPath 5.8 License vApp
- PowerPath License File
- RTools for Windows
Details:
- Deploy the vApp
- Generate a license file from EMC's website, you'll need the IP and DNS name of the vApp.
- or contact your EMC support team to have them do it for you.
- Copy the license file to the vApp's /etc/emc/licenses/ directory
- Install RTools on a Windows server or your workstation
- I prefer to have my tools on a shared general purpose system. This allows me to run scheduled scripts from one location.
- Copy the same license file to C:\ProgramData\My Documents\emc\PowerPath\rpowermt
- The rpowermt tool reads this location to find out the license server IP address and name.
- Now onto the Powershell portion of this post (Apologies for the formatting, I've been lazy in finding a new editor for Blogger):
#Connecting to vCenter Connect-VIServer YourvCenterServerName #Gather hosts in previously connected vCenter $VMHosts = Get-VMHost #Getting saved root credentials for esx hosts #To generate this, you can use the New-VICredentialStore cmdlet $VICreds = Get-VICredentialStoreItem -File D:\SomePath\RootCreds.xml #This is where we begin working w/ each individual VM host. Foreach ($VMHost in $VMHosts) { #Here we call the rpowermt executible, inserting the VM host name, and its root credentials #We are capturing the output of this command into the $LicenseChk variable $LicenseChk = & 'C:\Program Files (x86)\EMC\PowerPath\rpowermt\rpowermt.exe' check_registration host=$($VMHost.name) username=$($VICreds.User) password=$($VICreds.Password) #Here we call a switch and do a regex check of the contents of $LicenseChk switch -regex ($LicenseChk) { #If $LicenseChk contains the word unlicensed, we then attempt to register the VM host w/ the license server. #A check is made again, if the host is still unlicensed, we output the contents of $LicenseChk to a file and e-mail ourselves to investigate and attempt manual remediation #If licensed successfully, we check if a file denoting that has already been generated, if not we output the contents of $LicenseChk to a file. #This is simply for record keeping. "unlicensed" { & 'C:\Program Files (x86)\EMC\PowerPath\rpowermt\rpowermt.exe' register host=$($VMHost.name) username=$($VICreds.User) password=$($VICreds.Password) $LicenseChk = & 'C:\Program Files (x86)\EMC\PowerPath\rpowermt\rpowermt.exe' check_registration host=$($VMHost.name) username=$($VICreds.User) password=$($VICreds.Password) switch -regex ($LicenseChk) { "unlicensed" { $LicenseChk | Out-File -FilePath C:\SomePath\PowerPathRegistrationFailure$($VMHost.name).txt Send-MailMessage -SmtpServer yoursmtpserver.localdomain -To "AnEmailAddressyouOwn@somewhere.com" -From "ILikeDLs@somewhere.com" -subject "$($VMHost.Name) PowerPath License Failure" -Body "$($VMHost.Name) failed to register a powerpath license. Please attempt manually from someserveryourunthisfrom.localdomain" } "licensed" { If (Test-Path C:\SomePath\$($VMHost.name).txt ){} Else{$LicenseChk | Out-File -FilePath C:\SomePath\$($VMHost.name).txt } } } } "licensed" { If (Test-Path C:\SomePath\$($VMHost.name).txt ){} Else{$LicenseChk | Out-File -FilePath C:\SomePath\$($VMHost.name).txt } } } } #Once the loop completes, we disconnect from vCenter Disconnect-VIServer YourvCenterServerName -Confirm:$false
Comments
Do you have an example how RootCreds.xml should look like?
For example:
New-VICredentialStoreItem -Host whatever -user root -Password test -File D:\temp\rootcreds.xml
Host is a required parameter, but doesn't prevent you from using the generated xml against othere hosts w/ the same root creds.