Skip to content

Instantly share code, notes, and snippets.

@ChrisKader
Last active November 8, 2022 04:52
Show Gist options
  • Save ChrisKader/bad036b4bd326cd9974e3a4af478b079 to your computer and use it in GitHub Desktop.
Save ChrisKader/bad036b4bd326cd9974e3a4af478b079 to your computer and use it in GitHub Desktop.
Update PATH Environment Variable to include VS Codes CLI shortcuts

If you did not have the VS Code (Insiders) installer update your path (or you where not prompted due to installing via a package manager like winget), then you can use the below code to fix that.

This will update your systems PATH environment variable to include code or code-insiders.

  1. Execute the code below from within a VS Code (Insiders) PowerShell prompt.
  2. The script will output the code you then need to copy, paste and execute in a PowerShell CLI with elevated privilges.
switch((Test-Path "$Env:VSCODE_GIT_ASKPASS_NODE") -and ($Env:Path -split ';' -contains "$(Split-Path $Env:VSCODE_GIT_ASKPASS_NODE)\bin")) {$true{$codePath=Split-Path $Env:VSCODE_GIT_ASKPASS_NODE;Write-Host -ForegroundColor Green "`nExecute the below command (yellow text) from an PowerShell prompt with ELEVATED privileges`n"; Write-Host -ForegroundColor Yellow "`$Env:Path;[Environment]::SetEnvironmentVariable(`"Path`", `$Env:Path + `";$codePath\bin`", `"Machine`");`$Env:Path`n"} $false {Write-Host -ForegroundColor Red 'Path contains VS Code already or we cannot find the VS Code Path environment variable (VSCODE_GIT_ASKPASS_NODE)'}}

Formatted Code:

switch ((Test-Path "$Env:VSCODE_GIT_ASKPASS_NODE") -and ($Env:Path -split ';' -contains "$(Split-Path $Env:VSCODE_GIT_ASKPASS_NODE)\bin")) {
    $true {
        $codePath = Split-Path $Env:VSCODE_GIT_ASKPASS_NODE;
        Write-Host -ForegroundColor Green "`nExecute the below command (yellow text) from an PowerShell prompt with ELEVATED privileges`n";
        Write-Host -ForegroundColor Yellow "`$Env:Path;[Environment]::SetEnvironmentVariable(`"Path`", `$Env:Path + `";$codePath\bin`", `"Machine`");`$Env:Path`n"
    }
    $false {
        Write-Host -ForegroundColor Red 'Path contains VS Code already or we cannot find the VS Code Path environment variable (VSCODE_GIT_ASKPASS_NODE)'
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment