{"id":1418,"date":"2014-05-12T00:01:00","date_gmt":"2014-05-12T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2014\/05\/12\/introduction-to-powershell-scheduled-jobs\/"},"modified":"2014-05-12T00:01:00","modified_gmt":"2014-05-12T00:01:00","slug":"introduction-to-powershell-scheduled-jobs","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/introduction-to-powershell-scheduled-jobs\/","title":{"rendered":"Introduction to PowerShell Scheduled Jobs"},"content":{"rendered":"<p><b>Summary<\/b>: Microsoft Scripting Guy, Ed Wilson, introduces the Windows PowerShell scheduled job feature.<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. In all the hubbub about all the great features introduced in Windows PowerShell&nbsp;3.0, one (actually more than one) feature was somewhat overlooked. With Windows PowerShell&nbsp;3.0 bringing features such as workflow, PowerShell Web Access, support for disconnected sessions, CIM cmdlets, updatable Help, module auto loading, and improved Windows PowerShell ISE, it was really understandable that the scheduled job feature was simply overlooked by nearly everyone. This is not because the feature is bad&mdash;it is just that all the other way cool stuff left little room on the plate of the average IT pro.<\/p>\n<p style=\"margin-left:30px\"><b>Note&nbsp;<\/b> I have written quite a bit about scheduled tasks and Windows PowerShell over the years. I have written about the classic scheduled tasks and the newer task scheduler. For more information, see <a href=\"https:\/\/devblogs.microsoft.com\/scripting\/tag\/windows-powershell\" target=\"_blank\">this collection of blog posts<\/a>.<\/p>\n<h2>It&rsquo;s a job, it&rsquo;s a scheduled task&hellip;<\/h2>\n<p>Windows PowerShell scheduled jobs rely on the background jobs feature that was introduced in Windows PowerShell&nbsp;2.0. But unlike a plain old background job, Windows PowerShell&nbsp;3.0 added the ability to schedule the background job. This makes Windows PowerShell scheduled jobs like a cross between a Windows PowerShell background job and Task Scheduler tasks.<\/p>\n<p>Because Windows PowerShell scheduled jobs are, at their very heart, background jobs, it means that they run asynchronously in the background. It also means that I can use the <b>*job<\/b> cmdlets to manage Windows PowerShell scheduled jobs. Thereby, I protect my investment in learning Windows PowerShell in the first place. <b>Start-Job<\/b>, <b>Get-Job<\/b>, <b>Stop-Job<\/b>, and <b>Receive-Job<\/b> can be used to manage the Windows PowerShell scheduled jobs.<\/p>\n<p>In addition to the generic <b>*job<\/b> cmdlets, Windows PowerShell&nbsp;3.0 introduces a PSScheduledJob module that contains the following 16 cmdlets:<\/p>\n<p style=\"margin-left:30px\">PS C:\\&gt; Get-Command -Module PSScheduledJob | sort verb<\/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;&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; ModuleName<\/p>\n<p style=\"margin-left:30px\">&#8212;&#8212;&#8212;&#8211;&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\">Cmdlet&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Add-JobT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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PSScheduledJob<\/p>\n<p style=\"margin-left:30px\">Cmdlet&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Enable-JobTrigger&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; PSScheduledJob<\/p>\n<p style=\"margin-left:30px\">Cmdlet&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Get-ScheduledJobOption&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; PSScheduledJob<\/p>\n<p style=\"margin-left:30px\">Cmdlet&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Get-ScheduledJob&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; PSScheduledJob<\/p>\n<p style=\"margin-left:30px\">Cmdlet&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Get-JobTr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sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PSScheduledJob<\/p>\n<p style=\"margin-left:30px\">Cmdlet&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Remove-JobTrigger&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; PSScheduledJob<\/p>\n<p style=\"margin-left:30px\">Cmdlet&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set-ScheduledJobOption&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; PSScheduledJob<\/p>\n<p style=\"margin-left:30px\">Cmdlet&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set-ScheduledJob&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;PSScheduledJob<\/p>\n<p style=\"margin-left:30px\">Cmdlet&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set-JobTrigger&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; PSScheduledJob<\/p>\n<p style=\"margin-left:30px\">Cmdlet&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Unregister-ScheduledJob&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; PSScheduledJob<\/p>\n<h2>So, how does it work (or step-by-step)<\/h2>\n<p>Using the Windows PowerShell scheduled job cmdlets to create a scheduled job involves the following steps:<\/p>\n<ol>\n<li>Decide when to run the scheduled job.<\/li>\n<li>Decide how often to run the scheduled job.<\/li>\n<li>Decide what command to run.<\/li>\n<li>Create and configure the scheduled job.<\/li>\n<\/ol>\n<p style=\"margin-left:30px\"><b>Note&nbsp;<\/b> To create and schedule a Windows PowerShell scheduled job requires elevated permissions.<\/p>\n<p>I create a trigger, but when I try to register the scheduled job, if I have not opened Windows PowerShell with admin rights, the following error message appears:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-5-12-14-01.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-5-12-14-01.png\" alt=\"Image of error message\" title=\"Image of error message\" \/><\/a><\/p>\n<p>To launch with admin rights, right-click the Windows PowerShell icon and click <b>Run as Administrator<\/b>. The menu is shown in the following image:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-5-12-14-02.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-5-12-14-02.png\" alt=\"Image of menu\" title=\"Image of menu\" \/><\/a><\/p>\n<p>After I open the Windows PowerShell console with admin rights, I create the trigger, and I register the scheduled job. The script to do this is:<\/p>\n<p style=\"margin-left:30px\">$trigger = New-JobTrigger -Once -At 13:45<\/p>\n<p style=\"margin-left:30px\">Register-ScheduledJob -Name GPS -Trigger $trigger -ScriptBlock {GPS}<\/p>\n<p>This time, the command returns a <b>ScheduledJobDefinition<\/b> object. This object contains the name of the scheduled job, the job trigger, job ID, and the command itself. The command and the returned object are shown in the following image:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-5-12-14-03.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-5-12-14-03.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>I can now use the <b>Get-ScheduledJob<\/b> cmdlet to check the status of the scheduled job as shown here:<\/p>\n<p style=\"margin-left:30px\">PS C:\\&gt; Get-ScheduledJob -Id 1<\/p>\n<p style=\"margin-left:30px\">Id&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;JobTriggers&nbsp;&nbsp;&nbsp;&nbsp; Command&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;Enabled<\/p>\n<p style=\"margin-left:30px\">&#8212;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;&#8211;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&#8212;&#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8212;&#8211;<\/p>\n<p style=\"margin-left:30px\">1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GPS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GPS&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;True<\/p>\n<p>If I want to see what job options were used when creating the scheduled job, I use the <b>Get-ScheduledJobOption<\/b> cmdlet. This command and associated output are shown here:<\/p>\n<p style=\"margin-left:30px\">PS C:\\&gt; Get-ScheduledJobOption -Id 1<\/p>\n<p style=\"margin-left:30px\">StartIfOnBatteries&nbsp;&nbsp;&nbsp;&nbsp; : False<\/p>\n<p style=\"margin-left:30px\">StopIfGoingOnBatteries : True<\/p>\n<p style=\"margin-left:30px\">WakeToRun&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : False<\/p>\n<p style=\"margin-left:30px\">StartIfNotIdle&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : True<\/p>\n<p style=\"margin-left:30px\">StopIfGoingOffIdle&nbsp;&nbsp;&nbsp;&nbsp; : False<\/p>\n<p style=\"margin-left:30px\">RestartOnIdleResume&nbsp;&nbsp;&nbsp; : False<\/p>\n<p style=\"margin-left:30px\">IdleDuration&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 00:10:00<\/p>\n<p style=\"margin-left:30px\">IdleTimeout&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 01:00:00<\/p>\n<p style=\"margin-left:30px\">ShowInTaskScheduler&nbsp;&nbsp;&nbsp; : True<\/p>\n<p style=\"margin-left:30px\">RunElevated&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : False<\/p>\n<p style=\"margin-left:30px\">RunWithoutNetwork&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : True<\/p>\n<p style=\"margin-left:30px\">DoNotAllowDemandStart&nbsp; : False<\/p>\n<p style=\"margin-left:30px\">MultipleInstancePolicy : IgnoreNew<\/p>\n<p style=\"margin-left:30px\">JobDefinition&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Microsoft.PowerShell.ScheduledJob.ScheduledJobDefinition<\/p>\n<p>If I want to see what trigger was used for the scheduled job, I first get the scheduled job, and then I pipe it to the <b>Get-JobTrigger<\/b> cmdlet. This command is shown here:<\/p>\n<p style=\"margin-left:30px\">PS C:\\&gt; Get-ScheduledJob -Id 1 | Get-JobTrigger<\/p>\n<p style=\"margin-left:30px\">Id&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Frequency&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Time&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DaysOfWeek&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Enabled<\/p>\n<p style=\"margin-left:30px\">&#8212;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;&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; &#8212;&#8212;&#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;-<\/p>\n<p style=\"margin-left:30px\">1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Once&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5\/8\/2014 1:45:00 PM&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; True<\/p>\n<p>To see if the job ran, I use the <b>Get-Job<\/b> cmdlet as shown here:<\/p>\n<p style=\"margin-left:30px\">PS C:\\&gt; get-job<\/p>\n<p style=\"margin-left:30px\">Id&nbsp;&nbsp;&nbsp;&nbsp; Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PSJobTypeName&nbsp;&nbsp; State&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HasMoreData&nbsp;&nbsp;&nbsp;&nbsp; Location<\/p>\n<p style=\"margin-left:30px\">&#8212;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;&#8212;-&nbsp;&nbsp; &#8212;&#8211;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;&#8211;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8211;<\/p>\n<p style=\"margin-left:30px\">2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GPS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PSScheduledJob&nbsp; Completed&nbsp;&nbsp;&nbsp;&nbsp; True&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; localhost<\/p>\n<p style=\"margin-left:30px\">3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GPS1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PSScheduledJob&nbsp; Completed&nbsp;&nbsp;&nbsp;&nbsp; True&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; localhost<\/p>\n<p>I see there are two jobs that completed. So I look at the first job. Notice that this number is a different ID number than the one I received from <b>Get-ScheduledJob<\/b>:<\/p>\n<p style=\"margin-left:30px\">PS C:\\&gt; get-job -Id 2<\/p>\n<p style=\"margin-left:30px\">Id&nbsp;&nbsp;&nbsp;&nbsp; Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PSJobTypeName&nbsp;&nbsp; State&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HasMoreData&nbsp;&nbsp;&nbsp;&nbsp; Location<\/p>\n<p style=\"margin-left:30px\">&#8212;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;&#8212;-&nbsp;&nbsp; &#8212;&#8211;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;&#8211;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8211;<\/p>\n<p style=\"margin-left:30px\">2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GPS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PSScheduledJob&nbsp; Completed&nbsp;&nbsp;&nbsp;&nbsp; True&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; localhost<\/p>\n<p>To receive the results of the job, I use the <b>Receive-Job<\/b> cmdlet. To keep the results, I use the <b>&ndash;Keep<\/b> parameter. This will enable me to look at the results a second time. If I do not use the <b>&ndash;Keep<\/b> parameter, I will not be able to see the results a second time (unless I store the results in a variable or some other mechanism).<\/p>\n<p style=\"margin-left:30px\">Receive-Job -Id 2 -Keep<\/p>\n<p>The command and the output from the command are shown here:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-5-12-14-04.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-5-12-14-04.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>That is all there is to playing around with Windows PowerShell scheduled jobs. Scheduled Job 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>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, introduces the Windows PowerShell scheduled job feature. Microsoft Scripting Guy, Ed Wilson, is here. In all the hubbub about all the great features introduced in Windows PowerShell&nbsp;3.0, one (actually more than one) feature was somewhat overlooked. With Windows PowerShell&nbsp;3.0 bringing features such as workflow, PowerShell Web Access, support for [&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":[32,3,4,45],"class_list":["post-1418","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-scheduled-tasks","tag-scripting-guy","tag-scripting-techniques","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, introduces the Windows PowerShell scheduled job feature. Microsoft Scripting Guy, Ed Wilson, is here. In all the hubbub about all the great features introduced in Windows PowerShell&nbsp;3.0, one (actually more than one) feature was somewhat overlooked. With Windows PowerShell&nbsp;3.0 bringing features such as workflow, PowerShell Web Access, support for [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/1418","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=1418"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/1418\/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=1418"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=1418"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=1418"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}