Debugging a script launched by a Start-Process

Good day.

I tried to debug a script which is executed by Start-Process.

I inserted Write-Debug in the script and received the following error

[pre]Invalid handle.
Parameter name: handle
At C:\PS1\SaPwdChange\SaPwdChange.ps1:445 char:2

  • Write-Debug -Message ‘Lets debug’ -Debug [/pre]

Then i inserted Set-PSBreakpoint in the script and received basically the same Invalid handle error.

Powershell version is 5.1

What is a correct way of debugging a script executed by Start-Process?




Below documentation will help you to use Enter-PSHostProcess for debugging a PowerShell runspace in a different process.