{"id":2885,"date":"2013-09-11T00:01:00","date_gmt":"2013-09-11T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2013\/09\/11\/systems-center-2012-orchestrator-and-powershell-part-3\/"},"modified":"2013-09-11T00:01:00","modified_gmt":"2013-09-11T00:01:00","slug":"systems-center-2012-orchestrator-and-powershell-part-3","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/systems-center-2012-orchestrator-and-powershell-part-3\/","title":{"rendered":"Systems Center 2012 Orchestrator and PowerShell: Part 3"},"content":{"rendered":"<p><strong>Summary<\/strong>: Learn how to troubleshoot a Windows PowerShell script within Orchestrator.<\/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!<\/p>\n<p>I&rsquo;m having some trouble debugging my Windows PowerShell script in Orchestrator. Do you have any tips that might help us along?<\/p>\n<p>&mdash;DM<\/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 DM,<\/p>\n<p>Honorary Scripting Guy, Sean Kearney here. I continue to fill in for Ed this week while he &ldquo;branches out&rdquo; to new areas with his camera.<\/p>\n<p>So one thing you will have discovered if you have used Windows PowerShell with Orchestrator is that the Runbook Tester cannot view the Windows PowerShell objects. In fact, if you get an error message with your Windows PowerShell script in Orchestrator, you may very well be staring at some obscure looking .NET error message from the Windows PowerShell engine like this:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2867.01.png\"><img decoding=\"async\" title=\"Image of error message\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2867.01.png\" alt=\"Image of error message\" \/><\/a><\/p>\n<p>Looking at that is not very helpful. It doesn&rsquo;t tell me where in the script it failed, what it was doing, or the value of my objects. Only that it&hellip;well&hellip;FAILED.<\/p>\n<p>But remember, we are never lost in the world of Windows PowerShell. First off, let&rsquo;s think about how we built the script.<\/p>\n<p>You probably built it within some type of ISE with sample values and data to ensure that it actually worked outside of Orchestrator. Then at some point you copied in the script.<\/p>\n<p>So logically (if this is the exact script you started with), it must be something that is introduced by Orchestrator. Say for example a Variable or Published Data you subscribed to? Or possibly something your script is monitoring is coughing up a <strong>$Null<\/strong> value?<\/p>\n<p>Within Windows PowerShell, we have many built-in options for debugging. Within Orchestrator, you can start with the simplest approach, which is get the data out of the script into somewhere that you can examine it.<\/p>\n<p>The simplest method I have come across is to drop points in the script and have it export various variables by using <strong>Export-Clixml<\/strong>. That way if the script crashes, you&rsquo;ll have values from the script outside of Orchestrator with Date\/Time stamps.<\/p>\n<p>In the following sample script in Orchestrator, I have some lines that I can uncomment for testing purposes:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5428.02.png\"><img decoding=\"async\" title=\"Image of menu\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5428.02.png\" alt=\"Image of menu\" \/><\/a><\/p>\n<p>By Using the <strong>Export-Clixml<\/strong> to pull the data out, we get the object (how little or how much exists), so we can at least determine if we are getting the data we were supposed to be getting by diving into Windows PowerShell and examining these files like so:<\/p>\n<p style=\"padding-left: 30px\">[xml]$Filename=GET-CONTENT C:\\Debug\\Filename.xml<\/p>\n<p style=\"padding-left: 30px\">$Filename | GET-MEMBER<\/p>\n<p>We can examine the data and view it externally to see if we are receiving a Null, an array, or complete jibberish.<\/p>\n<p>We can also pull out two more options. We can temporarily Exit the script earlier to determine where the error actually is by using the <strong>Exit<\/strong> command.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8765.03.png\"><img decoding=\"async\" title=\"Image of menu\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8765.03.png\" alt=\"Image of menu\" \/><\/a><\/p>\n<p>This can at least tell us where things are going bad. If we can get the Runbook Tester to stop throwing errors, we can identify where in the script things are running poorly.<\/p>\n<p>The main trick, of course, is to ensure that the script works in the ISE. If your logic is broken before you plug it into Orchestrator, you&rsquo;ll have a bigger mess on your hands.<\/p>\n<p>Next time we&rsquo;ll look at some caveats and things to look out for when leveraging the two technologies.<\/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 email to <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>Sean Kearney, Honorary Scripting Guy<br \/> Windows PowerShell MVP<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Learn how to troubleshoot a Windows PowerShell script within Orchestrator. &nbsp;Hey, Scripting Guy! I&rsquo;m having some trouble debugging my Windows PowerShell script in Orchestrator. Do you have any tips that might help us along? &mdash;DM &nbsp;Hello DM, Honorary Scripting Guy, Sean Kearney here. I continue to fill in for Ed this week while he [&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,61,45],"class_list":["post-2885","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-guest-blogger","tag-sean-kearney","tag-weekend-scripter","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Learn how to troubleshoot a Windows PowerShell script within Orchestrator. &nbsp;Hey, Scripting Guy! I&rsquo;m having some trouble debugging my Windows PowerShell script in Orchestrator. Do you have any tips that might help us along? &mdash;DM &nbsp;Hello DM, Honorary Scripting Guy, Sean Kearney here. I continue to fill in for Ed this week while he [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/2885","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=2885"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/2885\/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=2885"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=2885"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=2885"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}