PS C:\> Set-PSBreakpoint -Command get-process -Script C:\fso\mydebug.ps1 The code and associated output are shown here: In the code that follows, I use the Set-PSBreakpoint cmdlet to set the breakpoint on the Get-Process cmdlet for the script c:\fso\mydebug.ps1. When the command Get-Process cmdlet appears, the script breaks and enters debug mode. If I run the script with the same name from a different location, the script will not break upon that command. I am going to set a breakpoint on a command on a script that appears in a specific location. Keep in mind that the path to the script matters. For the next several examples, I am going to use the script that is shown here: There are several ways to configure breakpoints. Repeats the last command if it was Step-into (s), Step-over (v), or List (l). Stops executing the script, and exits the debugger. ĭisplays lines of the script, beginning with the line number specified by. To continue listing the script, press Enter.ĭisplays 16 lines of the script beginning with the line number specified by. By default, it displays the current line, five previous lines, and 10 subsequent lines. The skipped statements are executed, but not stepped through.ĭisplays the part of the script that is executing. The skipped statements are executed, but not stepped through.Ĭontinues to run until the script is complete or until the next breakpoint is reached. If in the main body, it continues to the end or the next breakpoint. Steps out of the current function up one level, if nested. The skipped statements are executed, but not stepped through. The commands appear in the table that follows (this table is copied from my Microsoft Press book, Windows PowerShell 2.0 Best Practices book).Įxecutes the next statement and then stops.Įxecutes the next statement, but skips functions and invocations. This special mode permits the use of certain commands. When the script pauses execution, the Windows PowerShell console drops into debug mode. Today, I want to spend a little time looking at some of the things to do with one of the cmdlets.ĭebugging a Windows PowerShell script often involves setting a breakpoint, which is something that causes the Windows PowerShell script to pause execution. In Windows PowerShell 2.0, we introduced several Windows PowerShell cmdlets that make it easier to debug scripts. Every once in a while, however, the problem is not obvious, and being able to actually debug the script comes in helpful. I generally write code in such a way that when a problem occurs, it is obvious where the problem lies and how to correct it. Never have, even back in the VBScript days. To be honest, I rarely fire up a debugger. Invariably, when I am talking to people about writing Windows PowerShell scripts, someone comes up with the question about script debugging. But the best thing is getting to work with customers and talking to people about Windows PowerShell. When they say things like, “It snowed yesterday,” I grimace a little and reluctantly tell them it was 70 degrees Fahrenheit (21 degrees Celsius according to my unit conversion module) in sunny Southern California. One of the fun things about traveling, especially to warm places when it is winter back home, is calling to talk to friends and relatives. Summary: Learn how to use the Windows PowerShell script debugger to troubleshoot problems with scripts.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |