Home - Blogs - Orchestrator (Opalis) - Running PowerShell with the ‘Run Program' Activity from Orchestrator
Freitag, den 25. Mai 2012 um 09:19 Uhr

Running PowerShell with the ‘Run Program' Activity from Orchestrator

Artikel bewerten
(0 Bewertungen)

EDIT: This article applies to Orchestrator RTM. In Orchestrator SP1 or R2 you can simple run the command:  C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -c "Driveletter:\folder\PSScript.ps1"

Freitag, 25. Mai 2012 Stefan Horz

Yes, "Run .Net Script" is a powerfulActivity to run our own Powershell scripts within Runbooks, but ...

Sometimes it makes sense to start a PowerShell script with the 'Run Program' activity from System Center 2012 Orchestrator on a remote computer.
First the Excution Policy must be set to Remote Signed for the PowerShell of the remote Computer (PS> Set-ExecutionPolicy RemoteSigned).

When running the 'Run Program' activity with 'C:\Windows\system32\WindowsPowerShell\powershell.exe' as the program and the parameters '- File ' [] [] [...]’ the 'Run Program' Activity never ends.

Orchestrator Run Programm Activity Poweshell does not stopp

unless we modify the Activity to terminate after x minutes.
But if we look in the history log the Activity causes a warning then.

Orchestrator Run Programm Activity Poweshell causes warning


When we modify the Powershell Script File.ps1 putting at the end

$objCurrentPSProcess = [System.Diagnostics.Process]::GetCurrentProcess();
Stop-Process -Id $objCurrentPSProcess.ID;

modified PoerShell Script file

the 'Run Program’'Activity stops normally.

Running PowerShell with the ‘Run Program' Activity from Orchestrator

If we have no influence on this PowershellScriptFile.ps1 to start we can run it with the 'Run Program' activity and 'Command Execution Mode': like this:
cmd.exe /c | C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe –c [‘’] [‘’] […]

Running PowerShell with the ‘Run Program' Activity from Orchestrator

Read more

Kommentar hinterlassen