Apply to PowerShell 3.0 or higher!
PowerShell Ise only supports line breakpoints: It lets the script run to a specific debug line: You can press F9 to add or remove breakpoints. However, it is necessary to ensure that the script has been saved (the default untitled file may not be possible).
There is also a more advanced approach: a dynamic breakpoint, or a conditional breakpoint, which does not specifically qualify a row, but is limited to a particular scenario. For example, the following sample script, whenever PowerShell assigns a value to a specified variable, stops at the point of interruption:
Copy Code code as follows:
$BP = set-psbreakpoint-variable A-mode write-script $psise. Currentfile.fullpath
$a = 1
$a
$a
$a = 200
$a
Remove-psbreakpoint-breakpoint $BP
You can also bind more advanced and complex conditions, such as if you want to hit a breakpoint when an integer greater than 100 is assigned to $a:
Copy Code code as follows:
$Condition = {if ($a-is [Int]-and $a-gt) {break}}
$BP = set-psbreakpoint-variable A-mode write-script $psise. Currentfile.fullpath-action $Condition
$a = 1
$a
$a
$a = 200
$a
Remove-psbreakpoint-breakpoint $BP
Lai Non-moss NOTE: Conditional breakpoint This technique is quite unpopular, but it is very convenient when it is needed, for example, I assign a value to variable a in a slightly larger script file, but I do not know if I have assigned a wrong value, I want to find this line of code. If there is no conditional breakpoint, I may have to search the keyword for all variables a assignment statement, and hit the breakpoint, the project is vast, and if the use of conditional breakpoints, Amitabha!