# Set a line breakpoint on script in the remote session. PS C: > Enter-PSSession -ComputerName localhost # Create a new interactive session on the remote computer. # For demo purposes the remote machine is the local machine using ‘localhost’ as
# The local and remote computers must both be running Windows PowerShell 4.0.
Example 3: Console remote script debugging Instead, you will see it after you step through one more statement.įollowing are a few detailed examples to show you how remote debugging works. The downside is that some script output might arrive later than expected.įor example, if you step over a statement that generates output, you might not see that output at the next debugger stop. Because we didn’t want the output data to overwrite the prompt or other debugging information, Windows PowerShell suppresses script output data while the debugger is in Stop mode. When debug and output data are stopped in the debugger during remote script debugging, the data arrives at the client through separate and unsynchronized streams. There is one significant difference between local script and remote script debugging. PS C:> Enter-PSSession –ComputerName localhost Example 2: Create a new remote session and enter into an interactive session This is done by using the Enter-PSSession cmdlet, where you can enter an existing remote session or establish a new one. Debugging is an interactive endeavor, so to debug a script in a remote session, you must first establish an interactive session from which you can debug. Windows PowerShell remote script debugging provides an almost identical console debugging experience. Hit Line breakpoint on ‘C:DebugTest1.ps1:5’ PS C:> Set-PSBreakpoint –Script c:DebugTest1.ps1 –Line 5Įntering debug mode. You can examine script variables by typing the variable name and run new commands or script at the debug prompt…all while stopped in the debugger. The command prompt changes to indicate that the console is in debug mode, and from this prompt, you can execute debugger commands such as Help (‘h’, ‘?’), List source (‘list’, ‘l’), Show call stack (‘k’), and execution resume commands (for example, Continue, StepInto, and StepOut). When the breakpoint is hit, the script execution stops, and the console transitions into debugger mode. You use the Set-PSBreakpoint cmdlet to set a line, command, or variable breakpoint in a script, and then run the script. Script debugging in the Windows PowerShell console always begins in the same way. Check the program documentation for other host programs to learn if it is supported. Also, remote debugging is supported in the Windows PowerShell console, but it is not supported in the Windows PowerShell ISE. To use remote debugging, the client machine and the target machine must be running Windows PowerShell 4.0. In Windows PowerShell 4.0, you can set breakpoints in remote sessions and debug remote running scripts from the console in the same way that you debug local running scripts.
If you tried to set script breakpoints in a remote session, it caused an error. Previously, script debugging in Windows PowerShell was limited to scripts running on the local machine. This blog post describes the new remote debugging support, and a following post will describe the new workflow script debugging. Windows PowerShell 4.0 includes two major enhancements to the script debugger: script debugging now works in remote sessions, and we’ve added debugging support for workflow scripts.
Today we have a guest blog written by Paul Higinbotham who is a software design engineer on the Windows PowerShell team… Microsoft Scripting Guy, Ed Wilson, is here. Summary: Learn about remote debugging support in Windows PowerShell 4.0.