question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Current directory is included in PowerShell "launch" option; breaking launch configurations that run a command

See original GitHub issue

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.

Summary

I like to run PowerShell scripts into external windows. I have been using the same launch configs for years now without problem, but suddenly none of them now work. Here is an example launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "PowerShell",
            "request": "launch",
            "name": "PS5",
            "script": "Start-Process",
            "args": [
                "-FilePath ($Env:SystemRoot + '\\system32\\WindowsPowerShell\\v1.0\\powershell.exe')",
                "-Argumentlist '-NoExit -NoProfile -ExecutionPolicy Bypass -File \"${file}\"'"
            ]
        }
    ]
}

What should happen when running launching a .PS1 file with the debug option, is this:

PS C:\Test> Start-Process -FilePath ($Env:SystemRoot + '\system32\WindowsPowerShell\v1.0\powershell.exe') -Argumentlist '-NoExit -NoProfile -ExecutionPolicy Bypass -File "c:\Users\TestUser\desktop\TestScript.PS1"'

However it actually runs:

PS C:\Test> C:\Test\Start-Process -FilePath ($Env:SystemRoot + '\system32\WindowsPowerShell\v1.0\powershell.exe') -Argumentlist '-NoExit -NoProfile -ExecutionPolicy Bypass -File "c:\Users\TestUser\desktop\TestScript.PS1"'

Which of course leads to the error message:

C:\Test\Start-Process: The term 'C:\Test\Start-Process' is not recognized as a name of a cmdlet, function, script file, or executable program.

PowerShell Version

Name                           Value
----                           -----
PSVersion                      7.1.4
PSEdition                      Core
GitCommitId                    7.1.4
OS                             Microsoft Windows 10.0.19042
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visual Studio Code Version

1.59.1
3866c3553be8b268c8a7f8c0482c0c0177aa8bfa
x64

Extension Version

ms-vscode.powershell-preview@2021.8.2

Steps to Reproduce

Use the Launch config from above, and select it as the debug option. Then attempt to run any SAVED script.

Visuals

No response

Logs

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
andschwacommented, Sep 8, 2021

This fix is available in the preview that went out yesterday!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Start-Process (Microsoft.PowerShell.Management)
This example starts a process that uses the Sort.exe file in the current folder. The command uses all the default values, including the...
Read more >
Windows PowerShell Commands Cheat Sheet - Comparitech
We break down what Windows PowerShell is, and provide you a definitive downloadable PowerShell Commands Cheat Sheet (PDF) as a quick reference ...
Read more >
Run commands on your Windows instance at launch
When you launch a Windows instance in Amazon EC2, you can pass user data to the instance that can be used to perform...
Read more >
How to execute PowerShell commands from a batch file?
<# : Begin batch (batch script is in commentary of powershell v2.0+) @echo off : Use local variables setlocal : Change current directory...
Read more >
Windows PowerShell Cheat Sheet
In the Windows (File) Explorer address bar enter cmd , powershell.exe , or powershell_ise and a corresponding window opens at the current directory...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found