Orchestrator 2012 SP1 – PowerShell 3.0, Run .Net Activity and Get-SCXAgent

New things are not always good things or at least old habits change. I had been working on some runbooks in Orchestrator 2012 SP1 and needed to run PowerShell 3.0 and the .Net Activity. 

I installed Orchestrator 2012 SP1 on Windows Server2008 R2 which has PowerShell 2.0 installed natively. Then I wanted to use the Get-SCXAgent cmdlet and hit an error:

image

As I am a good person I installed PowerShell 3.0 and started to build the runbook. Well, somehow I didn’t get the result I expected in my output.  Next, I started digging around to see what’s wrong. If I executed the command in a regular shell (PowerShell 3.0) everything worked fine. I came across a post from Karl Prosser where he describes the problem.

Orchestrator executes it’s command still in PowerShel 2.0 instead PowerShell 3.0 if you use the Run .Net Activity. Because I wanted to see if this in Orchestrator SP1 still is an issue I build an easy runbook.

image

The first activity has two lines of code…

image

The second activity just dumps the results into a text file…

image

The first command is executed in a regular shell and the second command is executed in a sub shell . As the result shows, if you run regular PowerShell commands you will have a 2.o environment.

image

In order to have a PowerShell 3.0 environment for your Run .Net Script activity you need to call the script in a sub process and you can do that by executing the command like this…

$result = PowerShell { [Command]}

like

$PSEnv3 = PowerShell{$Host.Version}

Well, this issue is not brand new but still in Orchestrator SP1 something to be aware of.

15 Comments

  1. Thats the fourth Blog article i find regarding this issue.

    Everytime i use the $Var = powershell{Code} – trick, the runbooks hangs and never Exits.

    Im running Orchestrator 2012 R2 on Windows Server 2012 R2.

    Can someone confirm?

    I’m getting a Little bit tired that with every release the rules are changing for calling scripts in Orchestrator..

  2. Pingback: SCOM 2012 and Powershell 3.0 support for Server 2008 R2 agent managed systems | Crayon Services - The Blog

  3. Pingback: SCOM 2012 and Powershell 3.0 support for Server 2008 R2 agent managed systems | Binary-overflow-AI-||-&&-^

  4. I’m calling another PowerShell script inside a Run .NET activity. via dot sourcing. How can I make use of PowerShell { }? It doesn’t work for me, it complains
    The expression after ‘.’ in a pipeline element produced an invalid object. It must result in a command name, script block or CommandInfo object.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s