diff --git a/src/chocolatey.resources/helpers/functions/Set-EnvironmentVariable.ps1 b/src/chocolatey.resources/helpers/functions/Set-EnvironmentVariable.ps1 index 9fefb52cf5..84106ff364 100644 --- a/src/chocolatey.resources/helpers/functions/Set-EnvironmentVariable.ps1 +++ b/src/chocolatey.resources/helpers/functions/Set-EnvironmentVariable.ps1 @@ -15,8 +15,8 @@ function Set-EnvironmentVariable([string] $Name, [string] $Value, [System.EnvironmentVariableTarget] $Scope) { Write-Debug "Calling Set-EnvironmentVariable with `$Name = '$Name', `$Value = '$Value', `$Scope = '$Scope'" - if ($Scope -eq [System.EnvironmentVariableTarget]::Process) { - return [Environment]::SetEnvironmentVariable($Name, $Value, $Scope) + if ($Scope -eq [System.EnvironmentVariableTarget]::Process -or $Value -eq $null -or $Value -eq '') { + return [Environment]::SetEnvironmentVariable($Name, $Value, $Scope) } [string]$keyHive = 'HKEY_LOCAL_MACHINE'