Launch powershell scripts from events
AnsweredI'm having difficulty launching powershell scripts from events. Has anyone had success with this?
I've tried setting the launch target to: C:\windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe
and set the command argument to: -File "C:\ftproot\freespace.ps1" as well as omitting the -File.
Both fail with a log entry like
Process 'C:\windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe' executed with return code: 1 (failure)
I've also tried setting the launch target as a direct reference to the powershell script, which also fails with the following log entries:
[2020-11-05 14:18:41]: INFO [server] - []: - Monitor for process 'C:\ftproot\freespace.ps1' timed out
[2020-11-05 14:18:41]: INFO [server] - []: - Process 'C:\ftproot\freespace.ps1' executed with return code: 259 (failure)
I've also tried setting the launch target to: C:\Windows\System32\cmd.exe
with the command arguments of /c powershell -File C:\ftproot\freespace.ps1 (also tried without the -File)
[2020-11-05 14:35:31]: INFO [server] - []: - Process 'C:\Windows\System32\cmd.exe' executed with return code: 1 (failure)
I wrote a batch file (ps_launch.bat) which contains: powershell -file "C:\ftproot\freespace.ps1"
and tried having that launch as well.
INFO [server] - []: - Process 'C:\ftproot\ps_launch.bat' executed with return code: 1 (failure)
Other batch files are not failing.
My user account does not have any restrictions for launching powershell scripts
-
Hey Andrew,
We may want to open a ticket for this issue in case we need to troubleshoot further, but the first thing you will want to check is that the Cerberus Service in windows has permission to execute the script. If so, and it still cannot run, please let us know and I will generate a ticket from here.
Jeff
0 -
Thanks Jeff. I'll meet with our IT team later today to investigate those permissions
In the mean time, can you tell me which of those methods for launching scripts that I tried should have been expected to work?
After we adjust the permissions I want to make sure we run the correct test.
0 -
Hey Andrew,
You are welcome. Everything looks set up correctly. The event target points to C:\windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exeThe command is pointing to the PS1 file C:\ftproot\freespace.ps1. I would recommend that you test your script in Powershell. You may consider using https://www.scalyr.com/blog/getting-started-quickly-powershell-logging/ for logging purposes. This will help you troubleshoot any issues you run into.
0 -
The script runs fine manually and the service is running under my user so it should have the same permissions.
My IT team pointed me to this article which which shows a similar issue in an unrelated situation:
https://social.technet.microsoft.com/Forums/windows/en-US/65d5cf66-2d91-44ee-ada6-f7530897e42b/deploying-powershell-scripts-exit-code-1?forum=configmanagerapps
Adding -ExecutionPolicy ByPass to the command arguments fixed the problem.0
Please sign in to leave a comment.
Comments
4 comments