PowerTip: Debug Script on Remote Computer

PowerTip: Debug Script on Remote Computer

  • Comments 3
  • Likes

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.

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • I need to practice more.

    Thanks for sharing

  • Wonderful Tip!!! Let me test and enjoy PowerShell

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