Prerequisites
Steps to reproduce
Summary
In PowerShell 7.5+ on Windows, calling:
[Environment]::SetEnvironmentVariable($Name, $null, 'User')
does not completely remove the user environment variable.
Instead, it leaves behind an environment variable entry with an empty value.
This behavior did not occur in PowerShell 7.4.14 and earlier.
The issue has persisted across multiple versions since 7.5.
Steps to Reproduce
$Name = "TEST_ENV_VAR"
# Create variable
[Environment]::SetEnvironmentVariable($Name, "123", "User")
# Remove variable
[Environment]::SetEnvironmentVariable($Name, $null, "User")
After this, inspect the user environment variables:
[Environment]::GetEnvironmentVariables("User")
or check:
- System Properties → Environment Variables
- Registry:
HKEY_CURRENT_USER\Environment
Expected Behavior
The environment variable should be completely removed.
No variable named TEST_ENV_VAR should remain.
This is the behavior in PowerShell 7.4.14.
Actual Behavior
The variable name still exists, but its value becomes empty/null.
Example:
The registry entry is not fully deleted.
Environment
-
OS: Windows
-
Affected versions:
- PowerShell 7.5.x
- PowerShell 7.6.1
-
Last known good version:
Notes
This appears to be a regression introduced in PowerShell 7.5.
The issue may affect scripts or tools that rely on fully deleting environment variables rather than setting them to empty strings.
Expected behavior
The environment variable should be completely removed.
No variable named TEST_ENV_VAR should remain.
This is the behavior in PowerShell 7.4.14.
Actual behavior
The variable name still exists, but its value becomes empty/null.
Example:
TEST_ENV_VAR=
The registry entry is not fully deleted.
Error details
Environment data
Environment
OS: Windows
Affected versions:
PowerShell 7.5.x
PowerShell 7.6.1
Last known good version:
PowerShell 7.4.14
Visuals
This appears to be a regression introduced in PowerShell 7.5.
The issue may affect scripts or tools that rely on fully deleting environment variables rather than setting them to empty strings.
Prerequisites
Steps to reproduce
Summary
In PowerShell 7.5+ on Windows, calling:
does not completely remove the user environment variable.
Instead, it leaves behind an environment variable entry with an empty value.
This behavior did not occur in PowerShell 7.4.14 and earlier.
The issue has persisted across multiple versions since 7.5.
Steps to Reproduce
After this, inspect the user environment variables:
or check:
HKEY_CURRENT_USER\EnvironmentExpected Behavior
The environment variable should be completely removed.
No variable named
TEST_ENV_VARshould remain.This is the behavior in PowerShell 7.4.14.
Actual Behavior
The variable name still exists, but its value becomes empty/null.
Example:
The registry entry is not fully deleted.
Environment
OS: Windows
Affected versions:
Last known good version:
Notes
This appears to be a regression introduced in PowerShell 7.5.
The issue may affect scripts or tools that rely on fully deleting environment variables rather than setting them to empty strings.
Expected behavior
Actual behavior
Error details
Environment data
Visuals
This appears to be a regression introduced in PowerShell 7.5.
The issue may affect scripts or tools that rely on fully deleting environment variables rather than setting them to empty strings.