Debugging in the console
The PowerShell debugger allows code execution to be paused and the state of a script to be analyzed at a specific point.
These points are known as breakpoints and are set using the Set-PSBreakpoint
command.
PowerShell describes the following operations in the about_Debuggers
help file:
Get-Help about_Debuggers
The Set-PSBreakpoint
command can be used to set a breakpoint when a command is run, when a variable is used, or on a specific line in a saved script.
Setting a command breakpoint
Setting a breakpoint on a command will trigger the debugger when that command is run.
In the next example, a breakpoint is created that triggers when the Get-Process
command runs. As Get-Process
is inside a loop, it will be possible to inspect the state of variables inside the loop in the debugger:
Set-PSBreakpoint -Command Get-Process
$names = 'powershell', 'pwsh', 'code'
foreach ($name in $names) {
Get-Process...