Skip to content

PowerShellFar debugging

Roman Kuzmin edited this page Dec 14, 2025 · 3 revisions

VSCode debugger

The best debugging tool is the VSCode PowerShell extension. Configure its debugger: in global or local settings.json add the following entries to launch / configurations:

Attach to Far Manager main runspace using Bench/Start-FarDebug.ps1:

      {
        "type": "PowerShell",
        "request": "launch",
        "name": "Attach Far",
        "script": "Start-FarDebug.ps1"
      }

Or more generic (choose a Far Manager process interactively):

      {
        "type": "PowerShell",
        "request": "attach",
        "name": "Attach PowerShell",
        "runspaceId": 1
      }

Choose this debugger and start (F5). Set required breakpoints and run your PowerShell code in Far Manager. When breakpoints are hit, VSCode debugger opens the source at the hit breakpoint.

Known issues

Use the latest VSCode PowerShell. In older versions attaching may fail. #4843

Run VSCode as admin if Far Manager runs as admin. Otherwise attaching fails, either silently or with cryptic errors.

Breakpoints set in Far Manager may be removed on attaching. Set breakpoints in VSCode instead until the issue is fixed. #4489

If you use "Attach PowerShell" then commands in the terminal kind of hang until you hit Enter in Far Manager. "Attach Far" does not have this issue. #5347

On starting (F5) you may see the below message. PowerShell is not loaded yet, e.g. still loading or not loaded due to no .ps1 files in the workspace. Then try F5 in a few seconds. Or open VSCode in folders with some .ps1 files, e.g. scripts to be debugged.

Cannot debug or run a PowerShell script until the PowerShell session has started. Wait for the PowerShell session to finish starting and try again.

Add-Debugger.ps1

If VSCode is not an option for various reasons then use Add-Debugger.ps1. Get it from PSGallery and place in the path. Add-Debugger.ps1

This way looks unusual but debugging is quite robust. Also, it works when the usual debugging is tricky, e.g. debugging task code started by Start-FarTask.

With Start-FarTask you may use two debuggers at the same time:

  • Add-Debugger.ps1 debugger for code in the task runspace.
  • VSCode debugger for code in the main runspace, i.e. in job, run, ps: blocks.

Clone this wiki locally