GUIDE, Orchestrator, SCORCH

Making Orchestrator use the Windows native PowerShell version

Since System Center Orchestrator uses PowerShell version 2 it can become troublesome for some, especially when they want to run scripts or the integrated Run .Net Script activity in Orchestrator.

There’s at least two methods of doing this, one by editing in the Windows registry or by calling PowerShell from outside of Orchestrator.


Let’s make sure first what version of PowerShell Orchestrator is using before making any changes.

  1. Create a runbook.
  2. Add a Run .Net Script activity which can be found under the System activities.
  3. Edit the Run .Net Script activity and change the Type to PowerShell
  4. In the Script block we want to make a variable that will contain the PowerShell version.
  5. Navigate to Published Data to create the same named variable (String variable) as you did in the script block and then press Finish.
  6. To get the information about this variable we will need to enable extended logging, you can do this by right clicking your runbook and then choose Properties.
  7. Then navigate to the Logging tab, make sure to check the following box: Store Activity-specific Published Data and then press Finish.
  8. Run your runbook once, when the runbook has run you should see Successful event in the Log History at the bottom.
  9. Now open the log by double clicking the log entry in the Log History, a new window should open up.
  10. Double click the entry again and scroll down to the bottom until you find your variable name.
  11. As you can see the value is displayed as 2.0 which means Orchestrator is currently running PowerShell version 2.0.

Now let’s go through the first method to force Orchestrator to use Window’s native PowerShell version.

Method 1

  1. Go to Start and then type Regedit and press Enter.
  2. Go to the following registry path:
    HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework
    

  3. Create a new entry by right clicking the .NETFramework folder and choose New
    ->  DWORD (32-bit) Value.

  4. Set the value name to: OnlyUseLatestCLR
  5. Set the value data to: 1
  6. Now restart your Orchestrator server.
  7. Once you have restarted your Orchestrator server, re run your runbook that you previously created and see what version it will give.
    My result:

The second way of making Orchestrator use the Windows native PowerShell version is by calling PowerShell from within the Run .Net Script activity.

Method 2

  1. Create a runbook.
  2. Add a Run .Net Script activity which can be found under the System activities.
  3. Edit the Run .Net Script activity and change the Type to PowerShell
  4. In the Script block we will call powershell.exe from outside by writing the following:
    C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -nologo -command "&{C:\Scripts\YourScriptHere.ps1}"
    


  5. Change the path to correspond where your PowerShell scripts are located and then insert your script name at the end.
  6. Now just Check In your runbook and run it!

You can also download the guide in PDF version here.

 10,611 total views,  2 views today

11 thoughts on “Making Orchestrator use the Windows native PowerShell version”

  1. I tried this but orchestrator is using 32 bit version of the lastest powershell version. On my test environment orchestrator is using the 64 bit version. I still haven’t found the difference in configuration yet.

    1. Hi Frank,

      It should work, I’ve tested these in Orchestrator 2012, 2016, 1801 & 1807.

      Another method that you can try is the following:

      Invoke-Command -ComputerName localhost –
      #your code

      }2>&1
      IF ($Error) {throw New-Object System.Exception($Error)}

      Best regards,
      Leon

      1. I have used this Invoke-command before I switched to the registry change and I bumped into problems with scripts that need to run under different accounts and I got double hop problems… (ActiveDirectory script)

        So the registry change work for me on orchestrator 2016. But not on all environments. Still trying to find out what the difference is between the 2 environments. Same os, same patches, same scsm , ….

  2. Hi Leon,

    I used the method 2 and I have given the correct script path.

    But I found that script is not working in runbook. But when I ran the same ps script in ISE, it was working.

    In runbook, its not giving any error.

    Please assist.

    Regards,
    Gautam

  3. Hi Leon,

    I used the method 2. I have given correct script path and script is showing executed in runbook successfully.

    But that script is not working.

    But when I ran the same script in ISE, its working.

    Please help

    1. Hi Gautam,

      The best solution is to use a Run .Net Script and use the Invoke-Command within it, this will call a 64-bit powershell.exe.

      For example:


      $Result = Invoke-Command -ComputerName localhost {
      $Is64BitProcess = [Environment]::Is64BitProcess
      $PSVersion = $PSVersionTable.PSVersion
      RETURN $Is64BitProcess, $PSVersion
      }

      $64bit = $Result[0]
      $PSVersion = $Result[1]

      Best regards,
      Leon

  4. Hi Leon,

    Apologies. I am beginner. Can you explain me in simpler words. I found Method 2 easier.
    Above explanation I am not getting it.

    Please assist.

    Regards,
    Gautam

  5. In ISE , script is working where I am connecting to exchange. I am recalling this PS file in C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -nologo -command “&{C:\Scripts\YourScriptHere.ps1}” . But even runbook ran successfully , I am getting no output.

    Please assist. DO I need to change in runbook settings.

    1. When using the following: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -nologo -command “&{C:\Scripts\YourScriptHere.ps1}”
      in a Run .Net Script runbook activity, you will not receive any results, the only a result you will see is if the runbook activity itself managed to call the script or not, you will not receive any output from the YourScriptHere.ps1 that you are calling.

      You can instead try using a Run .Net Script runbook activity and use the Invoke-Command as I mentioned in my previous reply.
      If you have any more concerns, do feel free to create a question over here:
      https://social.technet.microsoft.com/Forums/en-US/home?category=systemcenterorchestrator

  6. Hi Leon,

    I used the method 1. It worked . You are genius.

    Thank u so much.

    Regards,
    Gautam

Leave a Reply

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