From ebda31df0aca6216dba4fa3f72dcd8f8afafc438 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Thu, 5 May 2016 18:37:50 -0500 Subject: [PATCH] (GH-724) Set Env Vars to empty should remove vars Removing environment variables sets empty environment variables. This is related to the changes for GH-303. So determine if the value is null or empty, and perform the older behavior. --- .../helpers/functions/Set-EnvironmentVariable.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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'