You can schedule a script in the Windows task scheduler to run automatically and perform a task without user intervention. You can schedule that script by using server manager or PowerShell. This post focuses on scheduling a script using PowerShell.

This article assumes you have already created a PowerShell script file (I'll use FindOutADUsers.ps1 here) the shall be scheduled.

Schedule a Script in Task Scheduler Using PowerShell

Step 1. Open the notepad editor and paste the following script. Save the file with the .ps1 extension

$Trigger= New-ScheduledTaskTrigger -At 12:00am -Daily #Trigger the task daily at 12 AM

$User= "yourdomain\administrator" #User

$Action= New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "C:\Users\Administrator.YOURDOMAIN\Desktop\FindOutADUsers\FindOutADUsers.ps1"

Register-ScheduledTask -TaskName "FindOutADUsers" -Trigger $Trigger -User $User -Action $Action -RunLevel Highest -Force

Step 2. Open PowerShell with elevated privileges and execute the above script.

How to Schedule a Script in Task Scheduler Using PowerShell

Karim Buzdar

About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. You can reach Karim on LinkedIn

Leave a Reply

Your email address will not be published. Required fields are marked *