Run script manually in Powershell vs Orchestrator

Artimes 346 Reputation points
2021-02-11T03:36:36.073+00:00

I created a script-action that should edit a word document (2016, 32-bit). The code of this script works as expected if run it in powershell (PS 5.1.14393.3866) manually same for starting script with Runbook-Tester. For sure I started powershell 32-bit in Orchestrator Runbook Service account context. But if Orchestrator (2016) starts the script it will not finish. I reduced the code example to a minimum. Orchestrator starts word as background task but never quit the application and the process is keep running till I close word via task manager.

$Word = New-Object -ComObject Word.Application
$Word.Visible = $true
Start-Sleep -s 10
$Word.Quit()

Are there different permissions between running script in Runbook-Tester or Powershell (service account context) and orchestrator?

EDIT: I guess the problem is that orchestrator run a powershell like a remote shell because the error pattern is the same as decribed here 7 years ago.

System Center Orchestrator
System Center Orchestrator
A family of System Center products that provide an automation platform for orchestrating and integrating both Microsoft and non-Microsoft IT tools.
216 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. XinGuo-MSFT 14,856 Reputation points
    2021-02-11T07:32:22.25+00:00

    Hi,

    What's your Orchestrator version?
    In my lab Orchestrator 2019, the following script could run success, the Word windows close after show 10 seconds.

    $Word = New-Object -ComObject Word.Application
     $Word.Visible = $true
    Start-Sleep -s 10
     $Word.Quit()
    
    1 person found this answer helpful.

  2. XinGuo-MSFT 14,856 Reputation points
    2021-02-15T06:50:34.56+00:00

    When we execute a runbook in the Runbook Tester it runs under your account. When Orchestrator runs it executes as the Orchestrator Runbook Service account.

    try
    {
    powershell.exe {$ENV:Username >>d:\context.txt }
    }
    catch [Exception]
    {
    $ErrorMessage = $_.Exception.Message
    }
    

    Getting detailed PowerShell Error information in Run .Net Activity

    1 person found this answer helpful.

  3. XinGuo-MSFT 14,856 Reputation points
    2021-02-15T08:58:34.183+00:00

    It's really weird, I shut down the process with the following command:

    $Word = New-Object -ComObject Word.Application
    $Word.Visible = $true
    Start-Sleep -s 10
    Stop-process -Name WINWORD
    #$Word.Quit()
    $ENV:Username >>d:\context.txt
    

    This article may help us understand this behavior.

    Word application quit not working