Cannot debug PowerShell scripts in Visual Studio Code
Closing all open PowerShell windows before pressing F5 fixed this issue for me.
You also may need to make sure that you don't have this Session exited warning:
If you do, click "Restart Current Session", then try pressing F5 again.
This is with the following config in launch.json (On a Windows 10 machine):
{ "name": "PowerShell: Launch script.ps1", "type": "PowerShell", "request": "launch", "script": ".\\script.ps1", "cwd": "${workspaceFolder}"}
To solve this problem, you can try to restart your current PowerShell session by:
- Opening the command pallet (
command
+shift
+p
) - Searching for Restart Current Session and selecting it
- Pressing the
F5
button again
You may see the issue pop up once more, but just press F5
again and you should see things start to execute.
This error message can pop up if your PackageManagement module isn't up to date, VSCode picks up on that, displays a pop-up on the lower right of the screen asking if you want to update and doesn't consider Powershell started until it's dismissed.