Tuesday, October 4
Shadow

powershell add to path

function append_to_path{
    param(
        [[string[]]]$list # list of paths
        [string]$path = $env:Path # path environment variable
    )

    foreach ($element in $list){
        $path += ";$element"
    }
}

[String[]] $path_list = @()

# example paths
$path_vscode="C:\Users\t\app\vscode\VSCode-win32-x64-1.70.2\bin"
$path_deno="C:\Users\t\app\deno"

# you could add the paths directly to the array without assigning to variable
$a += "/path/to/file"

# or assign to variables
$path_list += $path_vscode
$path_list += $path_deno

# manually
$env:Path += ";$path_vscode"
$env:Path += ";$path_deno"

# with function
# append_to_path -list $path_list

Leave a Reply