Powershell – How to run powershell script as Logon/logoff script on Windows 2003

powershellscheduled-taskscriptingwindows-server-2003

I've installed PowerShell Version 1.0 on my Windows 2003 server. How do I run a PowerShell script during logon or logoff event? I tried this through

Local Computer policy>User
Configuration>Windows
Settings>Logon/Logoff Scripts

But it doesn't seem to work.

Best Answer

You need to call the powershell binary directly with the scriptname. The example below assumes the .PS1 file is stored within directory assigned to the GPO. You will need to change the variables to match your environment.

powershell.exe -Command ". '\\%SYSVOL%\Policies\%POLICYGUID%\scriptname.ps1'"