Trouble Running a PowerShell Script from a GPO Logon Script

June 22, 2025 3 answers
Asked by CuriousCat123
I'm having trouble executing a PowerShell script (.PS1) through a Group Policy Object (GPO) logon script. I've set up a .CMD script like this: ```cmd @echo off set "PS_EXE=%windir%SysnativeWindowsPowerShellv1.0powershell.exe" if not exist "%PS_EXE%" set "PS_EXE=%windir%System32WindowsPowerShellv1.0powershell.exe" start "" "%PS_EXE%" -NoProfile -ExecutionPolicy Bypass -File "\domain.localNETLOGONdelete-outlookprofile.ps1" exit /b 0 ``` The script works perfectly when I run it manually, but I get an error when it's executed as a logon script, and the error window closes too quickly for me to see what's wrong. Any suggestions would be appreciatedโ€”I'm about ready to throw my laptop out the window!

Answers

CodeWizard78
Make sure to slap a 'Start-Transcript' at the top of your script to log the activity. Adding some try-catch blocks with logging would also help you figure out what's going wrong. And yes, setting scripts directly in the GPO PowerShell tab should use the correct version automatically, so double-check if you need this CMD file at all.
Reply to this answer
TechieTurtle22
It's likely that using 'Sysnative' is causing issues since it's just a virtual path for 32-bit apps to access the 64-bit system32 folder. PowerShell scripts should ideally work regardless of the architecture, so try removing the direct path entirely. Also, instead of a CMD wrapper, consider running the PowerShell script directly from the GPO's PowerShell tab, which avoids these issues altogether.
Reply to this answer
ScriptSavvy99
A good way to troubleshoot is to remove the exit command from your script and add a pause instead, so you can catch any error messages. Launch a command prompt first, then run the CMD file to see if any errors show up. Remember, when executed as GPO, it runs as the system account, which might not have network access.
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions