Set A PowerShell Script To Run On Unlock

I recently needed to schedule a PowerShell script to run whenever a user unlocked their PC. The environment was not controlled with Group Policy, so I followed these steps to manually create a trigger for my PowerShell script to run.

Open Task Scheduler
Located in Administrative Tools. You can also search for task scheduler on the Start page.


Create A New Task
Click the Create Task link on the right side of the Task Scheduler window.

Create A New Task


Name Your Task
Give your task a name you will recognize in the list of scheduled tasks on your PC. Various applications trigger their own tasks from this interface, so the list is often robust enough that non-generic names are important.

Name Your Task


Set The Trigger
Open the Triggers tab and click New. Change the Begin the task drop down to the On workstation unlock value. Be sure the Enabled checkbox is checked at the bottom of the New Trigger dialog box. Click OK.


Set The Action
Open the Actions tab and click New. Set the Action drop-down to Start a program. Then type powershell.exe in the Program/Script field. You do not need to browse to find the actual path to Powershell.exe.

In the Add arguments field, enter the filename of your script preceded by .\. For example, if your script name is run-me.ps1, then you should enter .\run-me.ps1. Do not enter the full path to your script.

In the Start in field, enter the path to your script, excluding the file name. For example, if the full path to script, including the filename of your script, is C:\jsmith\scripts\run-me.ps1 then you should enter C:\jsmith\scripts\ in the Start in field.

Create Action dialog box

Click OK and close the task properties box. The script is set to run.