functions/utils/Set-EnvVar.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function Set-EnvVar {
    param (
        [Parameter(Mandatory = $true)]
        [string]$Name,
        [Parameter(Mandatory = $true)]
        [AllowNull()]
        [AllowEmptyString()]
        [string]$Value,
        [Parameter(Mandatory = $false)]
        [ValidateSet('Machine', 'Process', 'User')]
        [System.EnvironmentVariableTarget]$Target = [System.EnvironmentVariableTarget]::User
    )
    
    [System.Environment]::SetEnvironmentVariable($Name, $Value, $Target)
}