question

SouravMukherjee-0298 avatar image
0 Votes"
SouravMukherjee-0298 asked SouravMSFT commented

Script doesn't work in Run .Net activity

I have a script which I need to run from the orchestrator's Run .Net activity . The script works fine when ran from the Powershell ISE . However , when I put the same script in the .Net activity of the SCORCH , it just wouldn't run . It keeps telling me 'This cmdlet is not recognized as any cmdlt , function or path'.

Could you please tell me what could be the possible reason behind this and how do I fix it please ?

windows-server-powershellmsc-orchestrator
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

StefanHorz avatar image
0 Votes"
StefanHorz answered StefanHorz commented

Hi,

Invoke-WebRequest was introduced in Windows PowerShell 3.0.
So, with Orchestrator 2012 R2, I would set OnlyUseLatestClr in the Registry of the System(s) with Orchestrator Runbook Service:

HKLM\SOFTWARE\Wow6432Node\Microsoft.NETFramework
Reg_DWORD: OnlyUseLatestCLR
Value: 1

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Stefan , I cannot possibly thank you enough for suggesting this. This seem to have solved the issue but not entirely. I can now run the script successfully when triggered through runbook tester but the issue still lingers when ran normally in the orchestrator. Any suggestions please ?

0 Votes 0 ·
StefanHorz avatar image StefanHorz SouravMukherjee-0298 ·

Hi @SouravMukherjee-0298,

thank you for you feedback! You're welcome!

When you run an Orchestrator Runbook with Runbook Tester it runs with the context (system and user) Runbook Designer is started. Otherwise the Runbook must be checked in and will be executed with a system which runs "Orchestrator Runbook Service".

I guess the system which executes the Runbook with Orchestrator Runbook Service is different from the system with Runbook Tester. OnlyUseLatestCLR must be set on every system which runs "Orchestrator Runbook Service".

Best regards,
Stefan


0 Votes 0 ·
StefanHorz avatar image
0 Votes"
StefanHorz answered SouravMukherjee-0298 commented

Hi,
can you paste the script here?

Which System Center Orchestrator Version do you use? Before System Center 2019 Orchestrator "Run .Net Script" Activity ist started Powershell Version 2.0.
AD-cmdlets for example require a higher version (3).
You can set OnlyUseLatestClr:
HKLM\SOFTWARE\Wow6432Node\Microsoft.NETFramework
Reg_DWORD: OnlyUseLatestCLR
Value: 1

Some cmdlets require 64bit. Until Version 2019 "Run .Net Script" Activity runs in 32-bit. Try to invoke the script with powershell {your script}.

The cmdlets must be available on Orchestrator Runbook Server.

Regards,
Stefan

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you for your response. I have tried invoking the whole script but still no luck. Pasting the script below FYR.



Could you please tell me , what else I could do to solve this. The 180192-script-image.pngscript works like a charm in powershell ISE.


0 Votes 0 ·
script-image.png (283.9 KiB)
SouravMukherjee-0298 avatar image
0 Votes"
SouravMukherjee-0298 answered SouravMSFT commented

The version of the orchestrator is 2012 R2 .

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I would recommend you to upgrade the SCORCH 2012 R2 to SCORCH 2016 or later and then use the following method to run the PowerShell script with 64 bit.
\
https://docs.microsoft.com/en-us/system-center/orchestrator/standard-activities/run-net-script?view=sc-orch-2019#execute-64-bit-powershell-cmdlets-with-run-net-script-activity

The other reason to upgrade is SCORCH 2012 R2 product will be soon out of support in 4 months.

https://docs.microsoft.com/en-us/lifecycle/products/microsoft-system-center-2012-r2-orchestrator

0 Votes 0 ·