Hyperion and PowerShell: Executing Remotely
In our last PowerShell post, we covered using the Outline Load Utility with Hyperion Planning from PowerShell. But, now we have MaxL scripts doing data loads and Outline Load Utility scripts doing meta-data loads and they are happening on two different servers. We need a nice way to join all of this together in a single batch process controlled by one server. This let’s us have a true start-to-finish process that we can rely on.
But wait…how do we do that exactly? First we have some pre-work to get out of the way before we can actually execute a process remotely. To execute a process remotely, PowerShell has an invoke command that will create a remote session on another server with specified credentials and then execute a script. First, log into the server on which you will be executing remote commands. Start PowerShell with Administrative rights and execute this command:
Enable-PSRemoting -Force
Because we are passing credentials, we need to keep our password out of plain text. So, let’s start by opening up PowerShell and executing this command to generate an encrypted copy of our password:
"YourPasswordGoesHere" | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString | Out-File "PasswordFile.pass"
One quick note on passwords. If you have special characters that cause login failures, use the ` as an escape character in front of your special character. I’m using the password to my Hyperion Service account from my Hyperion domain. This generates a nice new file that we’ll use to pass our password later. For now, let’s focus on the reason you’re here…free code:
############################################################################### #Created By: Brian Marshall #Created Date: 2/16/2016 #Purpose: Sample PowerShell Script for HyperionEPM.com ############################################################################### ############################################################################### #Variable Assignment ############################################################################### $PowerShellUsername = "Hyperion\hypservice" $PowerShellPasswordFile = "PasswordFile.pass" $PlanningComputerName = "HyperionPL" $PlanningCommand = {C:\Data\HyperionEPM\PowerShell\Blog2Sample1.ps1} ############################################################################### #Create Credential for Remote Session ############################################################################### $PowerShellCredential=New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $PowerShellUsername, (Get-Content $PowerShellPasswordFile | ConvertTo-SecureString) ############################################################################### #Create Remote Session Using Credential ############################################################################### $PlanningSession = New-PSSession -ComputerName $PlanningComputerName -credential $PowerShellCredential ############################################################################### #Invoke the Remote Job ############################################################################### $PlanningJob = Invoke-Command -Session $PlanningSession -Scriptblock $PlanningCommand echo $PlanningJob ############################################################################### #Close the Remote Session ############################################################################### Remove-PSSession -Session $PlanningSession
And there you have it…set our variables, create a new credential for our connection, use that credential to create a remote session, execute a job, and kill the session. So what happens when we execute this?
Uh oh…is the PG version of what I actually said when I received this nice little message. But, upon some research, it appears that the Outline Load Utility uses more than 150 MB of memory on execution. But, the default limit for a remote session is 150 MB. So now we have to connect to our remote server and start up a administrative command prompt. Once you’ve done that, execute this:
winrm set winrm/config/winrs @{MaxMemoryPerShellMB="2048"}
You should get something like this if it goes properly:
Now then…we can try again…
We have a winner! We have officially remotely executed an Outline Load Utility script…on another computer. Cool isn’t it?
Comments