Set PSdebug - PowerShell


The Set-PSDebug command in PowerShell allows you to control debug settings for scripts and commands. By enabling debug mode, you can monitor script execution and identify errors. It’s primarily used for troubleshooting and debugging complex PowerShell scripts.


Set-PSDebug [-NonInteractive] [-NoLogFile] [-Provider <name>] [-Scope <global|script|local>] [-Trace <boolean>]


| Option/Flag | Description | Default Value |
| -NonInteractive | Runs the debugger in a non-interactive mode, suitable for unattended debugging | $false |
| -NoLogFile | Suppresses the creation of a debug log file | $false |
| -Provider | Specifies the provider to enable debugging for | None |
| -Scope | Controls the scope of the debug settings. Can be global, script, or local | Local |
| -Trace | Enables or disables tracing for the current session | $false |


  1. Enable debugging for the current script:
Set-PSDebug -Scope Script
  1. Enable debugging for a specific provider:
Set-PSDebug -Provider FileSystem -Scope Global
  1. Run the debugger in non-interactive mode:
Set-PSDebug -NonInteractive

Common Issues

1. No debug log file created:

Ensure that the -NoLogFile parameter is not specified.

2. Debugging does not work for non-PowerShell scripts:

Set-PSDebug only works for PowerShell scripts (.ps1 files). For other script types, use the appropriate debugging tools for that language or environment.


Set-PSDebug can be combined with other commands like Debug-Command and Set-PSBreakpoint for advanced debugging scenarios. Example:

Set-PSDebug -Scope Global
Debug-Command -Command { Write-Host "This is a debugging session" }
  • Debug-Command: Starts the debugger on a specific command.
  • Set-PSBreakpoint: Sets breakpoints in a script or command.
  • Get-PSBreakpoint: Retrieves existing breakpoints.