-->

mandag 2. mai 2016

Running SMlets in Orchestrator as a user with privileges in SCSM

As described in SMlets on server without the SCSM console you can use the SMlets from codeplex on a server without the SCSM console. Particullary useful on an Orchestrator server used to automate different parts of Service Manager.

You can use your PowerShell scripts in a '.Net Activity'.

The question is if the Orchestrator service account has the permission to do anything in ServiceManager as the script default will run with this user account.

To come around this issue simply add Orchestrator variables containing the username and password of a service account with suitable privileges in Service Manager. In your .Net Activity you add the following lines of code to make all the cmdlets in the SMlets run under this account:

$RemoteUsername = '{RunAsUser_SM}'
$RemotePassword = {ConvertTo-SecureString 'RunAsPassword_SM}' -AsPlainText -Force
$SMCreds = New-Object System.Management.Automation.PSCredential($RemoteUsername, $RemotePassword) -ErrorAction:Stop
$PSdefaultParameterValues.Add("*SCSM*:Credential", $SMCreds)


The next obstacle might be your PowerShell ExecutionPolicy which will stop your script at importing the SMlets module. The ExecutionPolicy can be changed on the server by running PowerShell (x86) as an administrator and run the command

Set-ExecutionPolicy Unrestricted

This will be a global change on the server and might be against your companys policy. If you do not want to do this, you can add two more lines in your .net activity to bypass this

$var = Powershell -ExecutionPolicy Bypass {
  ....
  <your script here>
  ...
}

Your script will work, but you will loose the feedback from the script unless you pipe it back to $var