Tech done right – usually

Logon Script to automatically log off users after a specified timeframe with a warning beforehand

Using this script as a PowerShell Logon Script (via GPO / GPEDIT), you can force a logoff at after a specified timeframe and give a warning to the user X minutes beforehand. You’ll want to force hide the script window using ‘-windowstyle hidden’, otherwise they could just kill it and never get logged off.

1234567891011121314151617

# Logon Script that will auto-logoff a user after a specified amount of time has passed,# and will give a warning of the impending logoff at a specified amount of time beforehand.# The Warning Message has 10 second timeout so that the user can't postpone the logoff forever.$maxTime=8# hours$warnTime=5# minutes$msgTimeout=10# seconds$WarningMSG="NOTICE! You will be logged off automatically in $warnTime minutes. Please save your files."# ========================================================================================================# Calculate Time To Sleep$sleepyTime=$maxTime*60*60$warningTime=$warnTime*60Sleep-Seconds($sleepyTime-$warningTime)$wshell=New-Object-ComObject Wscript.Shell$wshell.Popup($WarningMSG,$msgTimeout,"Automatic Logoff Incoming...",0x0)Sleep-Seconds$warningTime# ADD LOGOFF CODE BELOW!
Logoff