Book Image

PowerShell Troubleshooting Guide

By : Mike Shepard
Book Image

PowerShell Troubleshooting Guide

By: Mike Shepard

Overview of this book

Table of Contents (15 chapters)
PowerShell Troubleshooting Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Debugging in the console


The Set-PSDebug cmdlet gives a good amount of detail, but getting to a particular point in the code requires you to add Set-PSDebug statements in the code (which you might not be able to do) or step through all of the code up until that point. Fortunately, there is another set of cmdlets that allows interactive debugging, the PSBreakPoint cmdlets:

  • Set-PSBreakPoint

  • Remove-PSBreakPoint

  • Get-PSBreakPoint

  • Enable-PSBreakPoint

  • Disable-PSBreakPoint

With Set-PSBreakpoint, it is easy to create a breakpoint to cause the execution to be suspended when a certain line is reached using the –Line parameter. One caveat is that the parameter sets including the –Line parameter, also include a mandatory script parameter that refers to a file on disk. This isn't much of a barrier in the console since we would generally be working with a script file.

Here's another sample script:

Write-Host "Script starting"
Foreach ($i in 1..10){
    Write-Host $i
    Write-Host "Inside the loop"
...