{"id":3006,"date":"2013-08-20T00:01:00","date_gmt":"2013-08-20T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2013\/08\/20\/powershell-workflow-for-mere-mortals-part-2\/"},"modified":"2013-08-20T00:01:00","modified_gmt":"2013-08-20T00:01:00","slug":"powershell-workflow-for-mere-mortals-part-2","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/powershell-workflow-for-mere-mortals-part-2\/","title":{"rendered":"PowerShell Workflow for Mere Mortals: Part 2"},"content":{"rendered":"<p><strong>Summary<\/strong><span style=\"font-size: 12px\">: Microsoft Scripting Guy, Ed Wilson, continues a five-part series about Windows PowerShell Workflow.<\/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;Hey, Scripting Guy! So Windows PowerShell Workflow seems pretty cool. But I am wondering if it is possible to use it to easily&nbsp;provide workflow types of things for remote computers? Is this possible?<\/p>\n<p>&mdash;BB<\/p>\n<p><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;Hello BB,<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. We are enjoying a cool stretch of weather here in Charlotte, North Carolina. In fact, we have the windows open. We are also enjoying our visiting&nbsp;friends from Hamburg, Germany. So not only do we have great weather, but we have great company.<\/p>\n<p><strong>Note<\/strong>&nbsp;&nbsp;&nbsp;This is the second in a five-part series of blog posts about Windows PowerShell Workflow for &ldquo;mere mortals.&rdquo; You should read <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2013\/08\/19\/powershell-workflow-for-mere-mortals-part-1.aspx\" target=\"_blank\">PowerShell Workflow for Mere Mortals: Part 1<\/a> before you read this post. For more information about workflow, see these Hey, Scripting Guy! Blog posts:&nbsp;<a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/tags\/workflow\/\" target=\"_blank\">Windows PowerShell Workflow<\/a>.&nbsp;<\/p>\n<h2>Parallel Windows PowerShell<\/h2>\n<p>One of the reasons for using a Windows PowerShell Workflow is to be able to easily execute commands in parallel. This can result in some significant time savings.<\/p>\n<p style=\"padding-left: 30px\"><strong>Note&nbsp;&nbsp;<\/strong>For an example of the time savings that are possible by using a Windows PowerShell Workflow and running commands in parallel, see the excellent post written by Windows PowerShell MVP, Niklas Goude, <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2012\/11\/20\/use-powershell-workflow-to-ping-computers-in-parallel.aspx\" target=\"_blank\">Use PowerShell Workflow to Ping Computers in Parallel<\/a><em>.&nbsp;<\/em><\/p>\n<p>To perform a parallel activity by using Windows PowerShell Workflow, use the <strong>Foreach<\/strong> keyword with the <strong>&ndash;Parallel<\/strong> parameter. This is followed by the operation and the associated script block. The following script illustrates this technique:<\/p>\n<p style=\"padding-left: 30px\">Foreach -Parallel ($cn in $computers)<\/p>\n<p style=\"padding-left: 30px\">&nbsp;{ Get-CimInstance -PSComputerName $cn -ClassName win32_computersystem }<\/p>\n<p>One of the things to keep in mind (as a major source of early frustration) is that when I call the <strong>Get-CimInstance<\/strong> cmdlet from within the script block of my parallel <strong>Foreach <\/strong>keyword, I have to use the automatically added <strong>PSComputerName<\/strong> parameter, not the <strong>ComputerName<\/strong> parameter I would normally use with the cmdlet. This is because this is the way that Windows PowerShell Workflow handles computer names. If I look at the command-line syntax for <strong>Get-CimInstance<\/strong>, I do not see the <strong>&ndash;&ndash;PSComputerName<\/strong> parameter at all.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4745.HSG-8-20-13-01.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4745.HSG-8-20-13-01.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>The nice thing is that if I forget to use <strong>&ndash;PSComputerName<\/strong>, and I try to run the Windows PowerShell Workflow, an error message appears. The message is detailed enough that it actually tells me the issue and tells me what I need to do to solve it.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0525.HSG-8-20-13-02.png\"><img decoding=\"async\" title=\"Image of error message\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0525.HSG-8-20-13-02.png\" alt=\"Image of error message\" \/><\/a><\/p>\n<p>When I rename the parameter in <strong>Get-CimInstance<\/strong>, I can run the workflow, and it does not generate any errors. This is shown here.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0131.HSG-8-20-13-03.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0131.HSG-8-20-13-03.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>The complete <strong>GetComputerInfo<\/strong> workflow is shown here:<\/p>\n<p style=\"padding-left: 30px\">Workflow GetComputerInfo<\/p>\n<p style=\"padding-left: 30px\">{<\/p>\n<p style=\"padding-left: 30px\">&nbsp;$computers = &#8220;server1&#8243;,&#8221;client1&#8221;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;Foreach -Parallel ($cn in $computers)<\/p>\n<p style=\"padding-left: 30px\">&nbsp;{ Get-CimInstance -PSComputerName $cn -ClassName win32_computersystem } }<\/p>\n<p>I call the workflow, and I am greeted with computer information for each of the servers with names I stored in the <strong>$computers<\/strong> variable. The script and the output from the script are shown here.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8304.HSG-8-20-13-04.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8304.HSG-8-20-13-04.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>BB, that is all there is to use Windows PowerShell Workflow on a remote computer. Windows PowerShell Workflow Week will continue tomorrow when I will talk about more cool workflow 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><strong>Ed Wilson, Microsoft Scripting Guy<\/strong>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, continues a five-part series about Windows PowerShell Workflow. &nbsp;Hey, Scripting Guy! So Windows PowerShell Workflow seems pretty cool. But I am wondering if it is possible to use it to easily&nbsp;provide workflow types of things for remote computers? Is this possible? &mdash;BB &nbsp;Hello BB, Microsoft Scripting Guy, Ed Wilson, [&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":[362,3,4,45,382],"class_list":["post-3006","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-powershell-3","tag-scripting-guy","tag-scripting-techniques","tag-windows-powershell","tag-workflow"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, continues a five-part series about Windows PowerShell Workflow. &nbsp;Hey, Scripting Guy! So Windows PowerShell Workflow seems pretty cool. But I am wondering if it is possible to use it to easily&nbsp;provide workflow types of things for remote computers? Is this possible? &mdash;BB &nbsp;Hello BB, Microsoft Scripting Guy, Ed Wilson, [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/3006","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=3006"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/3006\/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=3006"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=3006"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=3006"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}