SOLVED

Powershell issues running script from Windows Service 02/02 - job information is not available

Occasional Contributor

Hi,

I am facing problems executing some powershell scripts from a Windows Service.

 

Background

The Windows Service (started with an AD user) will execute a command (through Process Class).

It will launch a command like in the folder that we specify:

  • powershell .\<script name>.ps1 -param1 'param1' -param2 'param2'...

The <script name>.ps1 uses the cmdlet Start-Job to execute a ssh script in a Linux server.

 

Issue

Some information from the ChildJobs is not available after the jobs execute. E.g.:

  • Error property.
  • JobStateInfo.Reason property.

If we run the same command from a Command Prompt, we are able the get that information when the job fails!

 

We are iterating the failed jobs using:

Get-Job -ChildJobState Failed | ForEach-Object \{
  <error handling>
\}

 

Workaround

None.

 

Thanks in advance,

Tiago R.

 

 

 
 
 
 
1 Reply
best response confirmed by tarente (Occasional Contributor)
Solution
Solved!
The problem was that powershell was executing in 32-bits thru the service and in 64-bits when launched from the command prompt.
I copied the code in described in https://stackoverflow.com/questions/19055924/how-to-launch-64-bit-powershell-from-32-bit-cmd-exe to the beginning of the script and now works as expected.