Skip to content

Instantly share code, notes, and snippets.

Last active January 29, 2023 22:39
What would you like to do?
Set a temporary environment variable in PowerShell
#requires -version 5.1
#set a temporary environment variable
# example using the function alias and positional parameters: se rust_log debug
Function Set-EnvironmentVariable {
Param (
[Parameter(Position = 0, Mandatory)]
[Parameter(Position = 1, Mandatory)]
$splat = @{
Path = (Join-Path -Path env: -ChildPath $name)
Value = $Value
Passthru = $Passthru
Force = $true
Set-Item @splat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment