Importing Scheduled Task using Powershell

Today's topic? Powershell and Scheduled Tasks!

Powershell provides a much more friendlier way to interact with scheduled task using the ScheduledTask module than the sc.exe does, but lets go through the cmdlets in that module.

First we have the Enable/Disable-ScheduledTask that are used in order to enable or disable a task. Then there are the Start/Stop-ScheduledTask that start or stop a task when it's running.

We can use the Register/UnRegister-ScheduledTask in order to add or remove a task and Export-ScheduledTask in order to export a task to an XML file. Let me add a command that I find very useful when it comes to importing tasks from a file here:

Register-ScheduledTask -Xml (Get-Content 'C:\Temp\MyTask.xml' | Out-String) `
                       -TaskName "MyTask" `
                       -User 'user' `
                       -Password 'password' Force

First we get the content of the MyTask.xml file and then we register a new task named "MyTask" that will run under the user "user" using the "password" password.

There are also cmdlet that will create a task, task trigger, task action etc, and also set the properties of a task but I prefer configuring the task using Task Scheduler and then importing it on any other servers.

Popular posts from this blog

IIS Client Certificate Revocation Check Disable

How to Configure Message Forwarding on a Mailbox Level

Syslog Message Collection for OMS from sources that do not support the agent