Orchestrator Script Troubleshooting Xplat

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 Replies to “Orchestrator 2012 SP1 – PowerShell 3.0, Run .Net Activity and Get-SCXAgent

    1. Hi

      I have not tried it but you also could try to add

      Powershell -Version 3

      at the beginnig of your script. This will load PowerShell 3.0 inside the current shell.

      Cheers,

      Stefan

      1. Hi, thanks for help but unforgently it did not work 🙁 I have heared that powershell 3.0 activity is in the new azure ip. Could not verify, thank you and kind regards

  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..

    1. Bump! I also have the same issue.

      Running the script in Exchange Management Shell works fine. But not from within Orchestrator.

      Has anyone come up with a solution for this?

    2. When I tried this my RB was also hanging. After some tinkering around I found it was a bad character that was causing the v3 powershell to hang. We were using a music symbol for a delimiter. Once I replaced that with a more common character the RB finished just fine. This was the error that occurred:
      powershell : Cannot process xml from ‘Output’ stream of ‘C:WindowsSystem32WindowsPowerShellv1.0powershell.exe’: ‘♫
      ‘, hexadecimal value 0x0E, is an invalid character. Line 1, position 103.

      Hope that helps.

    1. It is tempting to try the registry trick, but it may have unintended consequences.

      See: https://connect.microsoft.com/PowerShell/feedback/details/525435/net-4-0-assemblies-and-powershell-v2

      “While it is possible to force PowerShell 2.0 to run with .NET Framework 4.0 using various mechanisms such as creating a config file for PowerShell or editing the registry, these mechanisms aren’t supported and can have negative side effects on other PowerShell functionality such as PowerShell remoting and cmdlets with mixed-mode assemblies.”

  2. 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 to scomfaq Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.