{"id":10871,"date":"2006-04-25T12:17:53","date_gmt":"2006-04-25T12:17:53","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2006\/04\/25\/debugging-monad-scripts-part-5-preferences-and-commandline-options\/"},"modified":"2019-02-18T13:25:05","modified_gmt":"2019-02-18T20:25:05","slug":"debugging-monad-scripts-part-5-preferences-and-commandline-options","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/debugging-monad-scripts-part-5-preferences-and-commandline-options\/","title":{"rendered":"Debugging Monad Scripts, Part 5: Preferences and Commandline Options"},"content":{"rendered":"<p>Did your command or script fail and\/or report an error?&nbsp; We hope to have a proper script debugger in a future version, but until then, MSH has some handy features to help you figure out what went wrong.&nbsp; In this series of blog entries, I will present some of those features.&nbsp; Thanks to Jim Truher [MSFT], Bruce Payette [MSFT], and Jeff Jones [MSFT] for their help in putting this together.<\/p>\n<p>See the Windows &#8220;Monad&#8221; Shell Beta 2 Documentation Pack (<a href=\"http:\/\/www.microsoft.com\/downloads\/details.aspx?FamilyID=8a3c71d1-18e5-49d7-952a-c55d694ecee3&amp;displaylang=en\"><font color=\"#0000ff\">http:\/\/www.microsoft.com\/downloads\/details.aspx?FamilyID=8a3c71d1-18e5-49d7-952a-c55d694ecee3&amp;displaylang=en<\/font><\/a>) for general information about Monad.<\/p>\n<p>Part 1: <a href=\"http:\/\/blogs.msdn.com\/monad\/archive\/2005\/11\/04\/489138.aspx\"><font color=\"#0000ff\">http:\/\/blogs.msdn.com\/monad\/archive\/2005\/11\/04\/489138.aspx<\/font><\/a>&nbsp;(Terminating vs. Non-Terminating Errors, ErrorRecord)<br \/>Part 2: <a href=\"http:\/\/blogs.msdn.com\/monad\/archive\/2005\/11\/08\/490130.aspx\"><font color=\"#0000ff\">http:\/\/blogs.msdn.com\/monad\/archive\/2005\/11\/08\/490130.aspx<\/font><\/a>&nbsp;($error)<br \/>Part 3: <a href=\"http:\/\/blogs.msdn.com\/monad\/archive\/2005\/11\/09\/490625.aspx\"><font color=\"#0000ff\">http:\/\/blogs.msdn.com\/monad\/archive\/2005\/11\/09\/490625.aspx<\/font><\/a>&nbsp;(write-host)<br \/>Part 4: <a href=\"http:\/\/blogs.msdn.com\/monad\/archive\/2005\/11\/09\/491035.aspx\"><font color=\"#0000ff\">http:\/\/blogs.msdn.com\/monad\/archive\/2005\/11\/09\/491035.aspx<\/font><\/a>&nbsp;(set-mshdebug)<\/p>\n<p>Jon Newman [MSFT]<\/p>\n<p><font size=\"2\"><font size=\"3\"><\/font><\/font>&nbsp;<\/p>\n<p><b><font size=\"2\"><font size=\"3\"><\/p>\n<p><b><font color=\"#000000\">Preferences and Commandline Options (Debug, Verbose etc.)<\/font><\/p>\n<p><\/b><\/font><\/b><font size=\"3\">Where set-mshdebug enables script tracing and step-step, Debug and Verbose output allow you to trace and suspend\/restart individual cmdlets. Many cmdlets contain verbose and debug information which they will only print if you explicitly request it; you can also call write-debug, write-verbose, and write-warning (also write-object, write-error and write-progress) in your script.<\/p>\n<p><font face=\"Courier New\">MSH C:\\temp&gt; $VerbosePreference<br \/><\/font><font face=\"Courier New\">SilentlyContinue<br \/><\/font><font face=\"Courier New\">MSH C:\\temp&gt; write-verbose test<br \/><\/font><font face=\"Courier New\">MSH C:\\temp&gt; $VerbosePreference = &#8220;Continue&#8221;<br \/><\/font><font face=\"Courier New\">MSH C:\\temp&gt; write-verbose test<br \/><\/font><font face=\"Courier New\">VERBOSE: test<br \/><\/font><font face=\"Courier New\">MSH C:\\temp&gt; $VerbosePreference = &#8220;Stop&#8221;<br \/><\/font><font face=\"Courier New\">MSH C:\\temp&gt; write-verbose test<br \/><\/font><font face=\"Courier New\">VERBOSE: test<br \/><\/font><font face=\"Courier New\">Write-verbose : Command execution stopped because the shell variable &#8220;VerbosePreference&#8221; is set to Stop.<br \/><\/font><font face=\"Courier New\">At line:1 char:14<br \/><\/font><font face=\"Courier New\">+ write-verbose &lt;&lt;&lt;&lt; test<br \/><\/font><font face=\"Courier New\">MSH C:\\temp&gt; $VerbosePreference = &#8220;Inquire&#8221;<br \/><\/font><font face=\"Courier New\">MSH C:\\temp&gt; write-verbose test<br \/><\/font><font face=\"Courier New\">VERBOSE: test<br \/><\/font><font face=\"Courier New\">Confirm<br \/><\/font><font face=\"Courier New\">Continue with this operation?<br \/><\/font><font face=\"Courier New\">[Y] Yes [A] Yes to All [H] Halt Command [S] Suspend [?] Help (default is &#8220;Y&#8221;): y<br \/><\/font><font face=\"Courier New\">MSH C:\\temp&gt; <\/font><\/p>\n<p><font color=\"#000000\">You can configure the behavior of debug, verbose and errors with both command-line options and preference variables. The following command-line <\/font>options are available on every cmdlet, and can be configured separately for each cmdlet:<\/p>\n<ul>\n<li>-Verbose: Print verbose output\n<li>-Confirm: Inquire whether to continue before the cmdlet makes a change\n<li>-Debug: Inquire whether to continue whenever any of the following occur: debug output, verbose output, warning output, non-terminating error, cmdlet makes a change\n<li>-ErrorAction &lt;ActionPreference&gt; : Request the &#8220;SilentlyContinue&#8221;, &#8220;Continue&#8221;, &#8220;Stop&#8221; or &#8220;Inquire&#8221; behavior when a non-terminating error occurs.<\/li>\n<\/ul>\n<p>Your preference choices are:<\/p>\n<ul>\n<li>&#8220;SilentlyContinue&#8221;: Ignore and continue\n<li>&#8220;Continue&#8221;: Print and continue\n<li>&#8220;Stop&#8221;: Halt the command or script\n<li>&#8220;Inquire&#8221;: Ask the user what to do<\/li>\n<\/ul>\n<p>You can also set preference variables which set the default behavior where the above command-line options are not specified. The actions which you can configure are:<\/p>\n<ul>\n<li>$VerbosePreference: for verbose output only\n<li>$ConfirmPreference: what to do before the cmdlet makes a change\n<li>$DebugPreference: for debug output only\n<li>$WarningPreference: for warning output only (default is to print warning output)\n<li>$ProgressPreference: for progress output only\n<li>$ErrorActionPreference: what t<font color=\"#000000\">o do when a non-terminating error occurs<\/font><\/li>\n<\/ul>\n<p><b><i><\/p>\n<p><\/b><\/i><font color=\"#000000\">Regardless of the ErrorAction settings, $error is always populated (whether you see a message or not):<\/font><\/p>\n<p><font face=\"Courier New\">MSH C:\\temp&gt; get-process -ErrorAction SilentlyContinue doesnotexist<br \/>MSH C:\\temp&gt; $error[0]<br \/>get-process : No process with process name &#8216;doesnotexist&#8217; was found.<br \/>At line:1 char:12<br \/>+ get-process&nbsp; &lt;&lt;&lt;&lt; -ErrorAction SilentlyContinue doesnotexist<br \/>MSH C:\\temp&gt;<\/font><font size=\"2\"><\/p>\n<p><\/font><\/font><\/font><\/p>\n<p>[<i>Edit: Monad has now been renamed to Windows PowerShell.  This script or discussion may require slight adjustments before it applies directly to newer builds.<\/i>]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Did your command or script fail and\/or report an error?&nbsp; We hope to have a proper script debugger in a future version, but until then, MSH has some handy features to help you figure out what went wrong.&nbsp; In this series of blog entries, I will present some of those features.&nbsp; Thanks to Jim Truher [&hellip;]<\/p>\n","protected":false},"author":600,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-10871","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell"],"acf":[],"blog_post_summary":"<p>Did your command or script fail and\/or report an error?&nbsp; We hope to have a proper script debugger in a future version, but until then, MSH has some handy features to help you figure out what went wrong.&nbsp; In this series of blog entries, I will present some of those features.&nbsp; Thanks to Jim Truher [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/10871","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/600"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=10871"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/10871\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=10871"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=10871"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=10871"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}