Powershell scripts no longer working
-
Hey @Russ! Long time!
Reformatted my HD, reinstalled Windows 10, then installed triggercmd and reconnected it as the same machine. I copied over the .triggercmd folder and all the scripts to the new environment. Everything comes up in the GUI properly. When I try to kick off a PowerShell command, it doesnt run. Nothing happens at all. No error. When I run the script outside triggercmd, it works without issue. The only thing in the script is a couple of Start-Process and Stop-Process commands.
When I look at the history of the command, it shows error 1.
I'm a full admin. Not sure why it's failing me when when it worked perfectly until now.
Anywhere that I can check logs to see what may be going on? Any ideas on what could be happening?
-
@kellanist, can you show me your command? I wonder if you need to prefix it with powershell or something, like:
powershell c:\scripts\yourscript.ps1
Also, please check your debug.log log for more output. I might give the reason it's failing and returning error code 1.
Also, please confirm you're on the latest version of the agent, which is 1.0.46 as of today.
-
This is the command Im using which has been working for years until I reformatted my machine:
powershell "C:\Users\MYUSER\Documents\TriggerCMDScripts\StartWork.ps1"
I checked the debug.log and I dont see any timestamps in there and when I click on the scripts, its not logging anything. Its like the button is doing nothing. I deleted the debug.log file and when it recreated, it didnt log anything other than the app starting and me opening the GUI editor.
Running the newest agent 1.0.46.
-
@kellanist, the debug.log should show something like this when running the command remotely, including from the green Trigger button on the website:
triggercmd.com data: { trigger: 'Logger', id: '656748449bbd61001bbde2f1', sender: 'website', params: null } Running trigger: Logger Command: d:\tools\logger.bat generic %date% %time% stdout: stderr:
Can you show me what happens when you run that command from a cmd prompt rather than a powershell prompt, and make sure it's running non-elevated, (aka not "as administrator"). I'm hoping that will fail in the same way and we'll see the error.
-
@Russ figured it out. Had a GPO that set the execution policy for the local machine. I had the computer added by name in the GPO. Looked at the GPO, and since I had to remove and re-add the "new" computer with the same name to the domain, it was showing the old entry in the GPO. Added the "new" computer name and it applied the correct execution policy to the local machine.
I didn't notice at first as I was using VS Code which just allowed the script to run.
However, I did fix it to make sure that even if the execution policy is set to restricted, it will still run. I used this command in TriggerCMD to get it to work.
powershell -executionpolicy bypass -file "C:\Users\MYUSER\Documents\TriggerCMDScripts\StartWork.ps1"
Thanks a ton for pointing me in the right direction. I appreciate all your help as always. Keep on being awesome.
-
@kellanist, great. That makes sense.