{"id":1585,"date":"2014-04-18T00:01:00","date_gmt":"2014-04-18T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2014\/04\/18\/windows-8-1-and-the-land-of-forgotten-modules-part-5\/"},"modified":"2014-04-18T00:01:00","modified_gmt":"2014-04-18T00:01:00","slug":"windows-8-1-and-the-land-of-forgotten-modules-part-5","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/windows-8-1-and-the-land-of-forgotten-modules-part-5\/","title":{"rendered":"Windows 8.1 and the Land of Forgotten Modules: Part 5"},"content":{"rendered":"<p><b>Summary<\/b>: Explore and discover the additional Windows PowerShell modules in Windows&nbsp;8.1.<\/p>\n<p>Honorary Scripting Guy, Sean Kearney, is here this week. Today, I&#039;ll wrap up our journey into the land of modules that are part of Windows 8.1. You also might enjoy reading:<\/p>\n<ul>\n<li><a href=\"\/b\/heyscriptingguy\/archive\/2014\/04\/14\/windows-8-1-and-the-land-of-forgotten-modules-part-1.aspx\" target=\"_blank\">Windows 8.1 and the Land of Forgotten Modules: Part 1<\/a><\/li>\n<li><a href=\"\/b\/heyscriptingguy\/archive\/2014\/04\/15\/windows-8-1-and-the-land-of-forgotten-modules-part-2.aspx\" target=\"_blank\">Windows 8.1 and the Land of Forgotten Modules: Part&nbsp;2<\/a><\/li>\n<li><a href=\"\/b\/heyscriptingguy\/archive\/2014\/04\/16\/windows-8-1-and-the-land-of-forgotten-modules-part-3.aspx\" target=\"_blank\">Windows 8.1 and the Land of Forgotten Modules: Part&nbsp;3<\/a><\/li>\n<li><a href=\"\/b\/heyscriptingguy\/archive\/2014\/04\/17\/windows-8-1-and-the-land-of-forgotten-modules-part-4.aspx\" target=\"_blank\">Windows 8.1 and the Land of Forgotten Modules: Part&nbsp;4<\/a><\/li>\n<\/ul>\n<p>Today I&rsquo;m going to investigate a module that I find particularly useful. One I would have dived over the table for this in my last job. Today, it&#039;s the Scheduled Tasks module.<\/p>\n<p>Let me grab the PowerShell can open&hellip;err&hellip;I mean, <b>Get-Command<\/b>, and crack open that module:<\/p>\n<p style=\"margin-left:30px\">Get-Command &ndash;Module ScheduledTasks<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0677.1.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0677.1.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>Right off the bat I see <b>New-ScheduledTask<\/b>. Now THAT would have saved me so much when I was trying to do this on servers. Schtasks.exe worked; but again, it was yet another tool that had its own way of doing things in the land of CMD.exe.<\/p>\n<p>But with Windows PowerShell&mdash;well, overall consistency is King in this world.<\/p>\n<p>If I grab a little Help, I can easily see the process for building out a task in Windows 8.1&mdash;just as I can get Help with any Windows PowerShell cmdlet:<\/p>\n<p style=\"margin-left:30px\">Get-Help New-ScheduledTask &ndash;Examples<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2475.2.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2475.2.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>There are quite a few pieces to set up, but I can easily see what pieces to modify to set up a task. It&rsquo;s pretty obvious that the application name is Taskmgr.exe, so I can easily plug in Notepad.exe by changing the name in <b>New-ScheduledTaskAction<\/b>:<\/p>\n<p style=\"margin-left:30px\">New-ScheduledTaskAction &ndash;Execute &ldquo;Notepad.exe&rdquo;<\/p>\n<p>Although, why I would schedule to launch Notepad automatically is beyond me&hellip;personally, I would be launching One Note instead.<\/p>\n<p>Because all of these are cmdlets,and getting Help is identical each time, if I need to see different ways to set up task triggers I would run <b>Get-Help<\/b> as normal:<\/p>\n<p style=\"margin-left:30px\">Get-Help New-ScheduledTaskTrigger &ndash;Examples<\/p>\n<p>Getting a list of tasks is now very easy in Windows PowerShell by using one cmdlet:<\/p>\n<p style=\"margin-left:30px\">Get-ScheduledTask<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4370.4.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4370.4.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>Now I can actually do some cleanup and find only tasks that are <b>Disabled<\/b> (which makes me wonder what they&rsquo;re doing on my computer right now):<\/p>\n<p style=\"margin-left:30px\">Get-ScheduledTask | where { $_.State &ndash;eq &lsquo;Disabled&rsquo; }<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2388.4.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2388.4.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>Or if prefer, I can find all tasks for <b>DiskDiagnostic<\/b>:<\/p>\n<p style=\"margin-left:30px\">Get-ScheduledTask &ndash;TaskPath \\Microsoft\\Windows\\DiskDiagnostic\\<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4135.5.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4135.5.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>Not too many there and both of them disabled. I could remove them&mdash;but let&rsquo;s do it the safe Windows PowerShell way. We&rsquo;ll use <b>&ndash;whatif<\/b> first:<\/p>\n<p style=\"margin-left:30px\">Get-ScheduledTask &ndash;TaskPath \\Microsoft\\Windows\\DiskDiagnostic\\ | Unregister-ScheduledTask &ndash;whatif<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4784.6.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4784.6.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>You didn&rsquo;t think I was actually going to delete stock tasks in Windows did you? Of course not. But a cool thing about using Windows PowerShell is you can play with the live data.<\/p>\n<p>Finally, the one thing I wish I had this for: A computer with the CPU maxed just right due to heavily scheduled and overlapped tasks.<\/p>\n<p>My first challenge: Suspend EVERYTHING running.<\/p>\n<p>Before Windows PowerShell, I had to manually poke through all of the scheduled tasks, find the ones that were running, then stop them one&hellip;by one&hellip;by one&hellip;<\/p>\n<p>Then scream like a Monty Python Gumby, &ldquo;Oh my brain! It hurts. It hurts!&rdquo; What a slow way to do things.<\/p>\n<p>However, we can now get all of those scheduled tasks by running one command:<\/p>\n<p style=\"margin-left:30px\">$TaskList=Get-ScheduledTask | where { $_.State &ndash;eq &lsquo;Running&rsquo; }<\/p>\n<p>&hellip;and then immediately stop them:<\/p>\n<p style=\"margin-left:30px\">$TaskList | Stop-ScheduledTask<\/p>\n<p>&hellip;and then disable them to bring things under control:<\/p>\n<p style=\"margin-left:30px\">$TaskList | Disable-ScheduledTask<\/p>\n<p>When I&rsquo;ve decided that it wasn&rsquo;t any of my scheduled tasks, but some badly written SQL query somebody wrote with <b>Select *<\/b> and multiple cross-table joins doing a client side filter, I simple re-enable them and let the system go back to its normal happy level of work:<\/p>\n<p style=\"margin-left:30px\">$TaskList | Enable-ScheduledTask<\/p>\n<p>Are you also curious about the status of task? You can pipe a list of tasks to <b>Get-ScheduledTaskInfo<\/b> and find out how they&rsquo;re doing. Let&rsquo;s check out the task for <b>Multimedia<\/b>:<\/p>\n<p style=\"margin-left:30px\">Get-ScheduledTask &ndash;TaskPath &lsquo;\\Microsoft\\Windows\\Multimedia\\&rsquo; | Get-ScheduledTaskInfo<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7S.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7S.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>Or I can get the same information for all of the tasks that have not been &ldquo;running so well&rdquo; (as they say):<\/p>\n<p style=\"margin-left:30px\">Get-ScheduledTask | Get-ScheduledTaskInfo | Where { $_.NumberOfMissedRuns &ndash;gt 0 } | Format-Table &ndash;Autosize<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6138.8.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6138.8.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>Pretty cool, eh? Why dig around for answers about your scheduled tasks when you can get Windows PowerShell to do the work for you?<\/p>\n<p>That&rsquo;s all we have in the Land of Forgotten Modules. Hopefully, there&rsquo;s a few pieces in there you might find handy.<\/p>\n<p>Remember, all of these modules are designed to also work in Windows Server&nbsp;2012&nbsp;R2&hellip;to make your life a little bit easier.<\/p>\n<p>Check back to this channel regularly for more exciting Windows PowerShell goodness!<\/p>\n<p>I invite you to follow The Scripting Guys 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 an email to The Scripting Guys 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 remember eat your cmdlets each and every day with a taste dash of creativity.<\/p>\n<p><b>Sean Kearney, <\/b>Windows PowerShell MVP and Honorary Scripting Guy&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Explore and discover the additional Windows PowerShell modules in Windows&nbsp;8.1. Honorary Scripting Guy, Sean Kearney, is here this week. Today, I&#039;ll wrap up our journey into the land of modules that are part of Windows 8.1. You also might enjoy reading: Windows 8.1 and the Land of Forgotten Modules: Part 1 Windows 8.1 and [&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":[56,154,45],"class_list":["post-1585","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-guest-blogger","tag-sean-kearney","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Explore and discover the additional Windows PowerShell modules in Windows&nbsp;8.1. Honorary Scripting Guy, Sean Kearney, is here this week. Today, I&#039;ll wrap up our journey into the land of modules that are part of Windows 8.1. You also might enjoy reading: Windows 8.1 and the Land of Forgotten Modules: Part 1 Windows 8.1 and [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/1585","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=1585"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/1585\/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=1585"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=1585"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=1585"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}