Last active
July 5, 2024 23:13
-
-
Save jdhitsolutions/43f16446e3ad73bcd237faf38764ddfc to your computer and use it in GitHub Desktop.
Set a temporary environment variable in PowerShell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#requires -version 5.1 | |
#set a temporary environment variable | |
# example using the function alias and positional parameters: se rust_log debug | |
Function Set-EnvironmentVariable { | |
[CmdletBinding(SupportsShouldProcess)] | |
[alias("se")] | |
Param ( | |
[Parameter(Position = 0, Mandatory)] | |
[ValidateNotNullOrEmpty()] | |
[string]$Name, | |
[Parameter(Position = 1, Mandatory)] | |
[object]$Value, | |
[switch]$Passthru | |
) | |
$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