Manage the Windows PATH environment variable with PowerShell

PHOTO EMBED

Fri Jul 15 2022 18:45:33 GMT+0000 (Coordinated Universal Time)

Saved by @sariohara

Function Add-PathVariable {
    param (
        [string]$addPath
    )
    if (Test-Path $addPath){
        $regexAddPath = [regex]::Escape($addPath)
        $arrPath = $env:Path -split ';' | Where-Object {$_ -notMatch 
"^$regexAddPath\\?"}
        $env:Path = ($arrPath + $addPath) -join ';'
    } else {
        Throw "'$addPath' is not a valid path."
    }
}
content_copyCOPY

adding a environment variable using powershell in vscode

https://www.techtarget.com/searchitoperations/answer/Manage-the-Windows-PATH-environment-variable-with-PowerShell