When trying to run a PowerShell script from EventSentry, the script hangs and never exits

Article ID: 198
Category: Application Scheduler
Applies to: All Versions
Updated: 2017-02-14

Due to a bug in powershell.exe (see additional links), any PowerShell script launched by EventSentry's application scheduler or process action will never terminate. As a result, you can neither retrieve the exit status nor the output from the script.

In order to launch PowerShell scripts from EventSentry you will need to wrap the powershell script in a batch file so that you can supply the -inputformat none parameter to powershell.exe. For example:

powershell -inputformat none "c:\scripts\eventsentry\dothis.ps1"

When logging to the console from your PowerShell script, make sure that you use the Write-Output, and not the Write-Host method.

In addition, if you haven't already done so, set the proper PowerShell execution policy on the system where the script will be executed, since running PowerShell scripts is disabled by default. The execution policy needs to be either set to "RemoteSigned" (recommended) or "Unrestricted". To set the execution policy, open an elevated PowerShell command prompt and run:

Set-ExecutionPolicy RemoteSigned

Your PowerShell script should now terminate correctly, allowing you to analyze the error code as well as the script's output.