I need to append an additional folder to my PATH environment variable when I run PowerShell from VisualStudio Code. This change should only exist when running PowerShell from within VisualStudio, since I don't want those extra utilities to be available otherwise (i.e. Updating the PATH variable in Windows settings is not an option.)

I made a few attempts at modifying my user settings but none seem to work.

Attempt 1

    "terminal.integrated.shell.windows" : "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
    "terminal.integrated.shellArgs.windows" : [
        "-Command \"$ {$Env:Path += ';C:\\tools'}\""

Result: PowerShell starts with the following error.

-Command : The term '-Command' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that
the path is correct and try again.
At line:1 char:1
+ -Command "$ {$Env:Path += 'C:\tools'}"
+ ~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (-Command:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Attempt 2

    "terminal.integrated.shell.windows" : "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
    "terminal.integrated.shellArgs.windows" : [
        "\"$ {$Env:Path += 'C:\\tools'}\""

Result: PowerShell starts with the following output, but the "C:\tools" dir is not appended to the PATH env variable.

$ {C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;... += 'C:\tools'}

Does anyone know how to invoke PowerShell with an expanded PATH variable from VisualStudio Code?

New contributor
trevanian is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

closed as off-topic by RockPaperLizard Jan 15 at 4:35

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.