{"id":53,"date":"2015-01-12T00:01:00","date_gmt":"2015-01-12T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2015\/01\/12\/use-powershell-to-show-results-of-scheduled-tasks\/"},"modified":"2019-02-18T10:36:02","modified_gmt":"2019-02-18T17:36:02","slug":"use-powershell-to-show-results-of-scheduled-tasks","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/use-powershell-to-show-results-of-scheduled-tasks\/","title":{"rendered":"Use PowerShell to Show Results of Scheduled Tasks"},"content":{"rendered":"<p><b style=\"font-size:12px\">Summary<\/b><span style=\"font-size:12px\">: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to see the results of scheduled tasks.<\/span><\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. It is snack time. For me, a perfect snack is a piece of biscotti and a cup of tea. Today, I am having such a snack&mdash;the tea is a nice green tea with a bit of jasmine flower in it. Lovely.<\/p>\n<p>Something else that is lovely is using the cmdlets from Scheduled Tasks module. This module contains a number of very helpful cmdlets.<\/p>\n<p style=\"margin-left:30px\"><b>Note<\/b>&nbsp; For a great overview of the Scheduled Tasks module, see <a href=\"https:\/\/devblogs.microsoft.com\/scripting\/windows-8-1-and-the-land-of-forgotten-modules-part-5\/\" target=\"_blank\">Windows 8.1 and the Land of Forgotten Modules: Part&nbsp;5<\/a>.<i><\/i><\/p>\n<h2 style=\"margin-left:30px\">Working with scheduled tasks<\/h2>\n<p>The Task Scheduler is very sophisticated. It is so sophisticated that many applications use it to run things at various times. If I want to get an idea of the tasks that are ready to run, it is going to require a lot of clicking in the GUI. But with Windows PowerShell, it is a piece of cake. I type a command such as the following&mdash;and voila! Lots of information appears.<\/p>\n<p style=\"margin-left:30px\">Get-ScheduledTask | where state -EQ &#039;ready&#039;<\/p>\n<p>The output is shown here:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-1-12-15-01.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-1-12-15-01.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>There are lots of scheduled tasks that are actually ready to run. What I if I want to find out the results of the last time the task ran? I know where to go in the GUI, but what about using Windows PowerShell? I look at cmdlets from the Scheduled Tasks module, and I see some things that make sense. Here are the results:<\/p>\n<p style=\"margin-left:30px\">PS C:\\&gt; Get-Command -Module ScheduledTasks -Verb get<\/p>\n<p style=\"margin-left:30px\">CommandType&nbsp;&nbsp;&nbsp;&nbsp; Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ModuleName<\/p>\n<p style=\"margin-left:30px\">&#8212;&#8212;&#8212;&#8211; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;-<\/p>\n<p style=\"margin-left:30px\">Function&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Get-ClusteredScheduledTask &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ScheduledTasks<\/p>\n<p style=\"margin-left:30px\">Function&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Get-ScheduledTask &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ScheduledTasks<\/p>\n<p style=\"margin-left:30px\">Function&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Get-ScheduledTaskInfo &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ScheduledTasks<\/p>\n<p>I suspect that I can use <strong>Get-ScheduledTaskInfo<\/strong>. So I give it a try. I know one of the scheduled tasks is <b>Consistency<\/b>.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-1-12-15-02.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-1-12-15-02.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>Dude. How rude! I mean, I KNOW the task name is <b>Consistency<\/b>, I just wrote a blog post about it ( see <a href=\"https:\/\/devblogs.microsoft.com\/scripting\/weekend-scripter-run-a-scheduled-task-to-check-dsc\/\" target=\"_blank\">Run a Scheduled Task to Check DSC<\/a>). I use the <b>Get-ScheduledTask<\/b> cmdlet to prove this:<\/p>\n<p style=\"margin-left:30px\">PS C:\\&gt; Get-ScheduledTask -TaskName consistency<\/p>\n<p style=\"margin-left:30px\">TaskPath &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TaskName &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; State<\/p>\n<p style=\"margin-left:30px\">&#8212;&#8212;&#8211; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8212;&#8212;&#8211; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#8212;&#8211;<\/p>\n<p style=\"margin-left:30px\">\\Microsoft\\Windows\\Desired State Configurat&#8230; Consistency &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Ready<\/p>\n<p>Yep. It is <b>Consistency<\/b> alright. What if I use the <b>&ndash;TaskPath<\/b> parameter? As shown here, it is now asking for the name. Dude&#8230;<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-1-12-15-03.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-1-12-15-03.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>I type the task name at the prompt, and finally I get the results of the last run. This is shown here:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-1-12-15-04.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-1-12-15-04.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>If I am going to go to all that trouble, I may as well just pipe <b>Get-ScheduledTask<\/b> in the first place:<\/p>\n<p style=\"margin-left:30px\">Get-ScheduledTask consistency | Get-ScheduledTaskInfo<\/p>\n<p>Cool. If I can pipe the results from <b>Get-ScheduledTask<\/b> to <b>Get-ScheduledTaskInfo<\/b>, I can make myself a report by piping the results to <b>Export-CSV<\/b>:<\/p>\n<p style=\"margin-left:30px\">Get-ScheduledTask | where state -EQ &#039;ready&#039; | Get-ScheduledTaskInfo | <br \/>Export-Csv -NoTypeInformation -Path C:\\fso\\scheduledTasksResults.csv<\/p>\n<p>Here is the output in Excel:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-1-12-15-05.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-1-12-15-05.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>Sweet. That was easy.<\/p>\n<p>That is all there is to using Windows PowerShell to find the results of scheduled tasks. Scheduled Tasks week will continue tomorrow when I will talk about more cool stuff.<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><b>Ed Wilson, Microsoft Scripting Guy<\/b><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to see the results of scheduled tasks. Microsoft Scripting Guy, Ed Wilson, is here. It is snack time. For me, a perfect snack is a piece of biscotti and a cup of tea. Today, I am having such a snack&mdash;the tea is a nice [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[31,32,3,45],"class_list":["post-53","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-operating-system","tag-scheduled-tasks","tag-scripting-guy","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to see the results of scheduled tasks. Microsoft Scripting Guy, Ed Wilson, is here. It is snack time. For me, a perfect snack is a piece of biscotti and a cup of tea. Today, I am having such a snack&mdash;the tea is a nice [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/53","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=53"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/53\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=53"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=53"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=53"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}