Building a Task
Last updated
Last updated
Things can get very complicated when building a task as there are several parameters to define, so its much easier to use Splatting to define the Variables. I suggest you get to know what Splatting is before going any further
I'll start with some basic information I need about the Scheduled Task. Since this Scheduled Task will run Admin level, it will need to run with Admin level access
This will be the Name of the Task you are creating in Task Scheduler
While not necessary, it keeps Tasks from cluttering up the ROOT of Task Scheduler. If you are creating several Tasks for your Organization, I recommend using a common root, such as 'Corporate'
Again, not necessary, but highly recommended so you know exactly what is happening in the Task. I recommend putting some Version information in the Description
In this example, I am going to create a Scheduled Task that will set the PowerShell ExecutionPolicy to Bypass ... so here is how things look
The Action is what is going to run in the Scheduled Task, which will be PowerShell with a Command
The Principal is the account that will be used to run the Scheduled Task. For this Task I will use SYSTEM at the Highest RunLevel. The Scheduled Task will run whether someone is logged in or not
This function will define the settings. For this Scheduled Task I want to make sure it will run whether the computer has AC power or is on Battery, as well as limiting it to running for a maximum of 60 minutes. Win8 Compatibility is for Windows 10, and multiple instances are run in Parallel (at the same time) if it is currently running
Once I have all of my settings defined, I can now splat the Scheduled Task variables
Registering a Scheduled Task is what publishes it into Scheduled Tasks. Its important to use the -Force
parameter as this will allow me to overwrite previous Tasks
With a complete script, run in PowerShell (as Admin) to create the Task
The screenshots below are the Scheduled Task Properties. The highlighted areas were modified as a result of the values from the PowerShell script
The Scheduled Task runs perfectly as an Administrator in the GUI, and it can also be run in PowerShell by usingStart-ScheduledTask
. You will need to specify the TaskPath
if the Task is not in the ROOT of Task Scheduler, or Get-ScheduledTask
and pipe it toStart-ScheduledTask
When logged in as a Standard User, the Task will not show up. This is due to the fact that the Task does not have permissions to run in a Standard User profile
The reason the Task does not show for the Standard User is that the Standard User does not have READ and EXECUTE permissions to the Scheduled Task. Time to read the next page