Public/Set-UserEnvironmentVariable.ps1
function Set-UserEnvironmentVariable { [CmdletBinding()] param ( [Parameter(Mandatory)] [string]$Name, [Parameter(Mandatory)] [string]$Value ) try { # Set at user scope (persists across sessions) [System.Environment]::SetEnvironmentVariable($Name, $Value, "User") # Set in current session Set-Item -Path "Env:\$Name" -Value $Value } catch { $PSCmdlet.ThrowTerminatingError($_) } } |