Working with Scheduled Tasks in Powershell on Windows Server 2008

Windows Server 2012 / Windows 8 and above include some nifty Powershell cmdlets for working with scheduled tasks.  However, when the need arises to programmatically work with them on older OS versions, mainly Windows Server 2008 , try out the code below.

Now that we have our $Task object, piping it into Get-Member we can see we can do quite a bit with it. Including enable / disable the task, get it’s status,  last run result, and more.

I admit it’s not as great as the cmdlets in the newer versions of Windows, but it has saved me quite a bit of trouble in more than few scripts.  Hope this helps, and happy scripting!

Bookmark the permalink.

5 Comments

  1. Thank you!
    Do you perhaps know how to invoke the Run and Stop methods? What arguments do they need?

  2. Thanks Ryan, that worked a treat. Much appreciated. I had a requirement for team members to run some server tasks ad-hoc after hours and wanted to avoid the task manager GUI. They are a good bunch but it’s just too risky, even with the best will in the world. Thanks to you I now have a couple of simple CMD scripts.

  3. This is amazing! Thank you very much for posting this! I would love to run a scheduled task on several servers without having to change the server name each time in the script (task name is the same across all servers). Does something like a variable, foreach and Get-content from a csv/txt file work with this script?

    • Yep should work using either get-content, import-csv, or input from another cmdlet (Like Get-ADComputer) and put that into a foreach loop.

      Glad it helped and good luck!

Leave a Reply

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