Automating the world one-liner at a time…
Did your command or script fail and/or report an error? 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. In this series of blog entries, I will present some of those features. Thanks to Jim Truher [MSFT], Bruce Payette [MSFT], and Jeff Jones [MSFT] for their help in putting this together.
See the Windows "Monad" Shell Beta 2 Documentation Pack (http://www.microsoft.com/downloads/details.aspx?FamilyID=8a3c71d1-18e5-49d7-952a-c55d694ecee3&displaylang=en) for general information about Monad.
Part 1: http://blogs.msdn.com/monad/archive/2005/11/04/489138.aspx (Terminating vs. Non-Terminating Errors, ErrorRecord)Part 2: http://blogs.msdn.com/monad/archive/2005/11/08/490130.aspx ($error)Part 3: http://blogs.msdn.com/monad/archive/2005/11/09/490625.aspx (write-host)Part 4: http://blogs.msdn.com/monad/archive/2005/11/09/491035.aspx (set-mshdebug)
Jon Newman [MSFT]
Preferences and Commandline Options (Debug, Verbose etc.)
MSH C:\temp> $VerbosePreferenceSilentlyContinueMSH C:\temp> write-verbose testMSH C:\temp> $VerbosePreference = "Continue"MSH C:\temp> write-verbose testVERBOSE: testMSH C:\temp> $VerbosePreference = "Stop"MSH C:\temp> write-verbose testVERBOSE: testWrite-verbose : Command execution stopped because the shell variable "VerbosePreference" is set to Stop.At line:1 char:14+ write-verbose <<<< testMSH C:\temp> $VerbosePreference = "Inquire"MSH C:\temp> write-verbose testVERBOSE: testConfirmContinue with this operation?[Y] Yes [A] Yes to All [H] Halt Command [S] Suspend [?] Help (default is "Y"): yMSH C:\temp>
You can configure the behavior of debug, verbose and errors with both command-line options and preference variables. The following command-line options are available on every cmdlet, and can be configured separately for each cmdlet:
Your preference choices are:
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:
Regardless of the ErrorAction settings, $error is always populated (whether you see a message or not):
MSH C:\temp> get-process -ErrorAction SilentlyContinue doesnotexistMSH C:\temp> $errorget-process : No process with process name 'doesnotexist' was found.At line:1 char:12+ get-process <<<< -ErrorAction SilentlyContinue doesnotexistMSH C:\temp>
[Edit: Monad has now been renamed to Windows PowerShell. This script or discussion may require slight adjustments before it applies directly to newer builds.]