Jump to Source of Error Message in VS Code from PowerShell

As a follow up to my previous post about opening PowerShell files and folders in Code from the PowerShell prompt, Bryan Dady reached out and offered the following trick as well.

In my sample script here I have a command on line 5 looking for a process that is clearly going to fail.

Get-Process -Name asdf

And here is the error message when I try to run it from PowerShell.  I have highlighted the section of the error that shows the line number where the error is occurring.

To jump right to that line in the script from PowerShell using VS Code we can run the following command:

 code -g D:\Test\ProcessFail.ps1:5 

And this will open in VS Code at the line number specified just like in the screenshot shown above.