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




Leave a comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.