Powershell – Create a Scheduled Task Using a Domain User as the Account

This script creates  a scheduled task running with elevated privileges, using a Domain User as the account  to run under.

One of my tasks is to install a  web based product using powershell. Part of that install is to schedule a powershell script to archive and prune logs. The script below will create a Scheduled task called CWS-ArchiveLogFiles, which will run on a daily basis as 12am and run a powershell script in C:\ScheduledTasks called CWS-ArchiveLogFiles.ps1.

It is based on a couple of “Scripting Guy” blogs (referenced in the code below)

basically if you want to assign a user and password to a scheduled task , this is the way vs “network service” or “builtin\administators”

Note: For passing parameters to the script

http://blogs.technet.com/b/heyscriptingguy/archive/2011/01/12/schedule-powershell-scripts-that-require-input-values.aspx

 

 

Leave a comment

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