PowerShell – Creating Scheduled Task from within your script

Creating a scheduled task on very large number of servers? Why not using a PowerShell script to do the job, using the “ScheduledTasks” – module. Lets make the module visible and point the various functions to the correct part of the task scheduler.

When taking a closer look at the module,  following functions are included.


We will discuss here only the functions that are needed to created a proper scheduled task on a your Windows machine. Lets go ahead and define the various functions of the module:

  • New-ScheduledTaskAction – function is related to the “Action” tab
    Information: link
    Actions Tab.PNG
  • New-ScheduledTaskTrigger – function is related to the “Triggers” tab
    Information: link
    Triggers Tab.PNG
  • New-ScheduledTaskPrincipal – function is related to the “Security Options” in the “General” tab.
    Information: link
    Security Options
  • Register-ScheduledTask – function will be used to add the Scheduled task to the task scheduler. More information see link
     [[-Password] ]
     [[-User] ]
     [[-TaskPath] ]
     [-Action] <CimInstance[]>
     [[-Description] ]
     [[-Settings] ]
     [[-Trigger] <CimInstance[]>]
     [[-RunLevel] ]
     [-CimSession <CimSession[]>]
     [-ThrottleLimit ]

     Example Code

    #Import Module ScheduledTasks
    Import-Module -Name "ScheduledTasks"
    #Define the task action parameters.
    $Sta = New-ScheduledTaskAction -Execute "powershell" -Argument ".\TestScript.ps1" -WorkingDirectory "C:\Scripts\"
    #Define the task trigger parameters. Task will start daily at 01AM.
    $Stt = New-ScheduledTaskTrigger -Daily -At 1am
    #Define the task principal
    $Stp =  New-ScheduledTaskPrincipal -UserId "SYSTEM" -RunLevel Highest -LogonType ServiceAccount
    #Variable includes description/TaskName for the scheduled task.
    $StTaskName="TEST SCRIPT 01"
    $StDescript="Schedule task that will launch a test script on the local machine"
    #Register the task in task scheduler.
    Register-ScheduledTask -TaskName $StTaskName -Action $Sta -Trigger $Stt -Principal $Stp -Description $StDescript 

    After running the script you will find a new task is the task scheduler. Task Scheduler General Result
    Task Scheduler triggers Result
    Task Scheduler Actions Result
    Have fun creating your scheduled tasks in a wink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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