PowerTip: Debug Script on Remote Computer

Summary: Use Windows PowerShell to debug a script on a remote computer. 

Hey, Scripting Guy! Question How can I use Windows PowerShell to debug a script on a remote computer?

Hey, Scripting Guy! Answer Use the debugging features in the Windows PowerShell 4.0 console:

1. Use Enter-PSSession to start an interactive session on the remote computer:

PS C: > Enter-PSSession -ComputerName Server01

2. Debug as usual. For example, set a line breakpoint on script in the remote session:

[Server01]: PS C:> Set-PSBreakpoint -Path C:DebugTest1.ps1 -Line 5

3. Run the script; it stops at the breakpoint:

[Server01]: PS C:> C:DebugTest1.ps1

Entering debug mode. Use h or ? for help. 

Hit Line breakpoint on ‘C:DebugTest1.ps1:5’

At C:DebugTest1.ps1:5 char:1

+ $Title = “Debugging Test”

+ ~~~~~~~~~~~~~~~~~~~~~~~~~

Note  The local and remote computers must be running Windows PowerShell 4.0.

Comments (3)

  1. Durval Ramos says:

    I need to practice more.

    Thanks for sharing

  2. Chen V says:

    Wonderful Tip!!! Let me test and enjoy PowerShell

  3. Chen V says:

    One small corretion Set-PSBreakPoint -Script iand not -Path parameter. Please correct me if I am wrong!!!