{"id":344,"date":"2014-11-16T11:59:00","date_gmt":"2014-11-16T11:59:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2014\/11\/16\/powertip-continue-a-windows-powershell-script-after-restart\/"},"modified":"2014-11-16T11:59:00","modified_gmt":"2014-11-16T11:59:00","slug":"powertip-continue-a-windows-powershell-script-after-restart","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/powertip-continue-a-windows-powershell-script-after-restart\/","title":{"rendered":"PowerTip: Continue a Windows PowerShell Script After Restart"},"content":{"rendered":"<p><b style=\"font-size:12px\">Summary<\/b><span style=\"font-size:12px\">: Learn how to continue a script after a remote system restart by using Windows PowerShell.<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Question\">&nbsp;I am configuring MPIO to automatically claim the iSCSI Bus Type, which requires a restart. However, I want to continue<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;automating afterward, so how do I continue my script from that point?<\/p>\n<p style=\"margin-left:30px\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Answer\">&nbsp;Introduced in Windows PowerShell&nbsp;4.0, you can use&nbsp;<b>Restart-Computer<\/b>&nbsp;with the&nbsp;<b>Wait<\/b>&nbsp;and&nbsp;<b>For<\/b>&nbsp;parameters. <br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;By default the&nbsp;<b>Restart-Computer&nbsp;<\/b>cmdlet uses DCOM as the protocol to perform the restart, so if WSMan is your <br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;only management protocol, you&rsquo;ll have to use the&nbsp;<b>Protocol<\/b>&nbsp;parameter and specify&nbsp;<b>WSMan<\/b>&nbsp;(as the following <br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;example illustrates). The&nbsp;<b>Wait<\/b>&nbsp;parameter is used to &ldquo;<b>Wait<\/b>&rdquo; &ldquo;<b>For<\/b>&rdquo; &ldquo;<b>PowerShell<\/b>&rdquo; to respond before continuing <br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;further in the script.<\/p>\n<p style=\"margin-left:90px\">Invoke-Command -ScriptBlock {Enable-MSDSMAutomaticClaim -BusType iSCSI} -ComputerName SVR01<br \/><span style=\"font-size:12px\">Restart-Computer -Protocol WSMan -Wait -For PowerShell -ComputerName SVR01<br \/><\/span><span style=\"font-size:12px\">Invoke-Command -ScriptBlock {Set-Service -Name MSiSCSI -StartupType Automatic} -ComputerName SVR01<\/span><\/p>\n<p style=\"margin-left:60px\"><b>Note<\/b>&nbsp; Today&rsquo;s PowerTip is supplied by Microsoft PFE, Brian Wilhite.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Learn how to continue a script after a remote system restart by using Windows PowerShell. &nbsp;I am configuring MPIO to automatically claim the iSCSI Bus Type, which requires a restart. However, I want to continue&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;automating afterward, so how do I continue my script from that point? &nbsp;Introduced in Windows [&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":[327,56,356,3,45],"class_list":["post-344","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-brian-wilhite","tag-guest-blogger","tag-powertip","tag-scripting-guy","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Learn how to continue a script after a remote system restart by using Windows PowerShell. &nbsp;I am configuring MPIO to automatically claim the iSCSI Bus Type, which requires a restart. However, I want to continue&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;automating afterward, so how do I continue my script from that point? &nbsp;Introduced in Windows [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/344","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=344"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/344\/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=344"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=344"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=344"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}