Update:

  • The solutions below work in Windows PowerShell and PowerShell (Core) 7 up to v7.4.x

  • PowerShell v7.5+ is based on .NET 9+, which introduces a breaking change where only passing a null as the value to the [Environment]::SetEnvironmentVariable() overload that will remove an environment variable from the current process:

    • In PowerShell, you'll need to use [NullString]::Value[1] rather than "" or $null when calling this .NET API directly in order to remove an environment variable; e.g.:

      Copy# In v7.5+, only [NullString]::Value actually *removes* the variable.
      [Environment]::SetEnvironmentVariable('HTTP_PROXY', [NullString]::Value)
      
      • Note: If you use '' (the empty string), you'll now get the following behavior:
        • With the (default) Process scope, i.e. for in-process environment variables, the variable will be created with (or set to) to the empty string.
        • With the persistent User or Machine scopes (supported on Windows only), a registry value that defines the variable with an empty string value technically is created, but such a value has no effect and is tantamount to removal of the variable; the reason is that when Windows instantiates a process' environment based on the persisted definitions in the registry, it ignores those whose value is the empty string.
    • As per the decision published here, v7.5+ surfaced this breaking change PowerShell-natively too; that is:

      • Only assigning $null, i.e. $env:HTTP_PROXY = $null in the case at hand, will result in an environment variable's removal going forward.

      • $env:HTTP_PROXY = '' will define this variable as / set it to the empty string rather than removing it.


In-process removal:

$env:HTTP_PROXY=''
$env:HTTPS_PROXY=''
[Alternatively (though it's simpler to use e.g., rm env:HTTP_PROXY):]
Set-Location Env:
rm HTTP_PROXY
rm HTTPS_PROXY

The statements above remove the specified environment variables from the current session (process) only.

Note:

  • On Unix-like platforms you'd have to use alias ri instead of rm, or use the cmdlet's full name, Remove-Item, instead; e.g., without using Set-Location first, ri Env:HTTP_PROXY.

  • See also: about_Environment_Variables.

However, if these environment variables are defined persistently, via the registry (on Windows), they will resurface in future sessions.


Persistent removal (Windows only):

[Environment]::SetEnvironmentVariable('HTTP_PROXY', '', 'User')
[Environment]::SetEnvironmentVariable('HTTPS_PROXY', '', 'User')
[Environment]::SetEnvironmentVariable('HTTP_PROXY', '', 'Machine')
[Environment]::SetEnvironmentVariable('HTTPS_PROXY', '', 'Machine')

The statements above - assuming they execute without triggering an exception - do remove the persistent definitions (on Windows only).

  • Note that setting / removing machine-level variables ('Machine') requires elevation (running as admin).

  • [See update at the top] By design, any of the following values causes the specified environment variable to be deleted: '', [NullString]::Value (the equivalent of null in C#[1]), "`0" (a single NUL (0x0) char.)

    • As an aside: This permissiveness is problematic, as it prevents creating environment variables whose value is the empty string, which is not uncommon on Unix-like platforms - see GitHub issue #50554.
  • Note that these methods remove only the persistent definitions of these variables - any definitions in the current session (process) are left untouched; to also remove them, use the methods at the top.

If the environment variables unexpectedly still resurface in future sessions, there are two potential causes:

  • Perhaps you started a new session directly from the old session, e.g. with Start-Process powershell.exe - in that case the current session's environment variables are inherited by the new session, so unless you've removed the environment variable from the current session as well, the new session will see them.

  • There may be code in your profile files, notably $PROFILE, that (re)defines these environment variables whenever a new session starts.

    • To rule out this possibility, use the Windows Run dialog (WinKey-R) and submit powershell -noprofile, then check if these variables are still present.

[1] PowerShell does have a $null constant that is generally the equivalent of C#'s null, but in a string context PowerShell forces $null values to '' (the empty string). Therefore, the [NullString]::Value singleton is required in order to pass a genuine null value to a string-typed .NET method parameter.

Answer from mklement0 on Stack Overflow
Top answer
1 of 3
32

Update:

  • The solutions below work in Windows PowerShell and PowerShell (Core) 7 up to v7.4.x

  • PowerShell v7.5+ is based on .NET 9+, which introduces a breaking change where only passing a null as the value to the [Environment]::SetEnvironmentVariable() overload that will remove an environment variable from the current process:

    • In PowerShell, you'll need to use [NullString]::Value[1] rather than "" or $null when calling this .NET API directly in order to remove an environment variable; e.g.:

      Copy# In v7.5+, only [NullString]::Value actually *removes* the variable.
      [Environment]::SetEnvironmentVariable('HTTP_PROXY', [NullString]::Value)
      
      • Note: If you use '' (the empty string), you'll now get the following behavior:
        • With the (default) Process scope, i.e. for in-process environment variables, the variable will be created with (or set to) to the empty string.
        • With the persistent User or Machine scopes (supported on Windows only), a registry value that defines the variable with an empty string value technically is created, but such a value has no effect and is tantamount to removal of the variable; the reason is that when Windows instantiates a process' environment based on the persisted definitions in the registry, it ignores those whose value is the empty string.
    • As per the decision published here, v7.5+ surfaced this breaking change PowerShell-natively too; that is:

      • Only assigning $null, i.e. $env:HTTP_PROXY = $null in the case at hand, will result in an environment variable's removal going forward.

      • $env:HTTP_PROXY = '' will define this variable as / set it to the empty string rather than removing it.


In-process removal:

$env:HTTP_PROXY=''
$env:HTTPS_PROXY=''
[Alternatively (though it's simpler to use e.g., rm env:HTTP_PROXY):]
Set-Location Env:
rm HTTP_PROXY
rm HTTPS_PROXY

The statements above remove the specified environment variables from the current session (process) only.

Note:

  • On Unix-like platforms you'd have to use alias ri instead of rm, or use the cmdlet's full name, Remove-Item, instead; e.g., without using Set-Location first, ri Env:HTTP_PROXY.

  • See also: about_Environment_Variables.

However, if these environment variables are defined persistently, via the registry (on Windows), they will resurface in future sessions.


Persistent removal (Windows only):

[Environment]::SetEnvironmentVariable('HTTP_PROXY', '', 'User')
[Environment]::SetEnvironmentVariable('HTTPS_PROXY', '', 'User')
[Environment]::SetEnvironmentVariable('HTTP_PROXY', '', 'Machine')
[Environment]::SetEnvironmentVariable('HTTPS_PROXY', '', 'Machine')

The statements above - assuming they execute without triggering an exception - do remove the persistent definitions (on Windows only).

  • Note that setting / removing machine-level variables ('Machine') requires elevation (running as admin).

  • [See update at the top] By design, any of the following values causes the specified environment variable to be deleted: '', [NullString]::Value (the equivalent of null in C#[1]), "`0" (a single NUL (0x0) char.)

    • As an aside: This permissiveness is problematic, as it prevents creating environment variables whose value is the empty string, which is not uncommon on Unix-like platforms - see GitHub issue #50554.
  • Note that these methods remove only the persistent definitions of these variables - any definitions in the current session (process) are left untouched; to also remove them, use the methods at the top.

If the environment variables unexpectedly still resurface in future sessions, there are two potential causes:

  • Perhaps you started a new session directly from the old session, e.g. with Start-Process powershell.exe - in that case the current session's environment variables are inherited by the new session, so unless you've removed the environment variable from the current session as well, the new session will see them.

  • There may be code in your profile files, notably $PROFILE, that (re)defines these environment variables whenever a new session starts.

    • To rule out this possibility, use the Windows Run dialog (WinKey-R) and submit powershell -noprofile, then check if these variables are still present.

[1] PowerShell does have a $null constant that is generally the equivalent of C#'s null, but in a string context PowerShell forces $null values to '' (the empty string). Therefore, the [NullString]::Value singleton is required in order to pass a genuine null value to a string-typed .NET method parameter.

2 of 3
8

A shorter alternative that can be used also in scripts:

Copyrm Env:HTTP_PROXY

rm Env:HTTPS_PROXY

That way you don't change location when removing the environment variables

🌐
Microsoft Learn
learn.microsoft.com › en-us › powershell › module › microsoft.powershell.core › about › about_environment_variables
about_Environment_Variables - PowerShell | Microsoft Learn
PowerShell can access and manage environment variables in any of the supported operating system platforms. The PowerShell Environment provider lets you get, add, change, clear, and delete environment variables in the current console.
Discussions

Need to remove an entry from $env:path
Plenty of ideas, but no need to reinvent the wheel . Edit: link to the full function . More on reddit.com
🌐 r/PowerShell
8
3
January 4, 2024
Delete a value in system variable path
Hello, I am wondering if you could point me in the right direction, I am trying to figure out how to remove/delete a single value of the Path variable in System Environment. As you know, the Path variable usually has multiple values, I don’t want to remove all the values, just one particular one. More on community.spiceworks.com
🌐 community.spiceworks.com
8
8
March 18, 2020
[Environment]::SetEnvironmentVariable(..., $null, 'User') does not fully remove user environment variables since PowerShell 7.5
The environment variable should be completely removed. No variable named TEST_ENV_VAR should remain. This is the behavior in PowerShell 7.4.14. The variable name still exists, but its value becomes empty/null. ... The registry entry is not fully deleted. More on github.com
🌐 github.com
10
1 month ago
Removing items from $env:PATH
http://ss64.com/ps/syntax-env.html http://stackoverflow.com/questions/714877/setting-windows-powershell-path-variable Methods differ depending on whether you need to change it only for the current session. Edit: found a better description of Machine environment variables, which are tied to the computer as a whole, and Process environment variables, which are restricted to a single process. http://technet.microsoft.com/en-us/library/ff730964.aspx More on reddit.com
🌐 r/PowerShell
2
7
June 23, 2014
People also ask

How to set an environment variable using PowerShell?

To set an environment variable, you can use the following syntax.

$Env:VariableName = “Value”

Replace VariableName with the desired name of your variable and Value with the value you want to assign to it, as example below.

$Env:MY_VAR = “MyValue”

🌐
netwrix.com
netwrix.com › home › resources › blog › powershell environment variables
PowerShell Environment Variables
How to check if an environment variable exists in PowerShell?

To check if a specific environment variable exists, you can use the following command.

Test-Path Env:MY_VAR Replace MY_VAR with the name of the environment variable you want to check. If the variable exists, it will return True; if not, it will return False.

🌐
netwrix.com
netwrix.com › home › resources › blog › powershell environment variables
PowerShell Environment Variables
How do I list all variables in PowerShell?

To list all variables in your PowerShell session, you can use:

Get-ChildItem Env:

This command will show all currently defined variables in the session, including environment variables.

🌐
netwrix.com
netwrix.com › home › resources › blog › powershell environment variables
PowerShell Environment Variables
🌐
Windows 10 Forums
tenforums.com › tutorials › 121797-delete-user-system-environment-variables-windows.html
Delete User and System Environment Variables in Windows - Windows 10 Help Forums
November 16, 2018 - (see screenshot below) ... in Registry Editor, right click or press and hold on the value name (ex: "Downloads") of the variable you want to delete for your account, and click/tap on Delete....
🌐
Get-carbon
get-carbon.org › Remove-EnvironmentVariable.html
PowerShell - Remove-EnvironmentVariable - Carbon
Uses the .NET Environment class to remove an environment variable from the Process, User, or Computer scopes.
🌐
IT Pro Today
itprotoday.com › powershell › powershell-one-liner-deleting-environment-variables
PowerShell One-Liner: Deleting Environment Variables
ITPro Today, Network Computing and IoT World Today have combined with TechTarget.com. The page you are looking for may no longer exist.
🌐
Reddit
reddit.com › r/powershell › need to remove an entry from $env:path
r/PowerShell on Reddit: Need to remove an entry from $env:path
January 4, 2024 -

If you enter the following in PowerShell

$env:path -split ';'

There is an entry that I would like to remove completely whilst leaving everything else intact.

Let's say for arguments sake the entry I wanted removing is: C:\Windows\System32\OpenSSH

How would I achieve this?

The only command I know is Remove-ItemProperty, which will remove an entire value.

I found the following which didn't work

$path = $env:Path
$newpath = $path.replace("C:\Windows;","")
$env:Path = $newpath

Any ideas how this can be achieved?

Find elsewhere
🌐
Eleven Forum
elevenforum.com › windows support forums › tutorials
Delete Environment Variables in Windows 11 | Windows 11 Forum
November 20, 2024 - (see screenshot below) 4 When finished ... You must be signed in as an administrator to use this option 1 Open Windows Terminal (Admin), and select Windows PowerShell....
🌐
Netwrix
netwrix.com › home › resources › blog › powershell environment variables
PowerShell Environment Variables
August 25, 2025 - To delete an existing environment variable, you can use the Remove-Item cmdlet. ... This command will remove variable from the environment variables, you can use Get-Item cmdlet to verify.
🌐
NinjaOne
ninjaone.com › home › blog › it ops › how to safely delete environment variables in windows 11
How to Safely Delete Environment Variables in Windows 11 | NinjaOne
March 12, 2026 - To delete a system‑level variable ... To validate via CMD, use set or echo %VAR_NAME% to verify removal. For PowerShell, use $env:VAR_NAME....
🌐
Microsoft Learn
learn.microsoft.com › en-us › powershell › dsc › reference › psdscresources › resources › environment › removevariable
Remove an environment variable - PowerShell | Microsoft Learn
With Ensure set to Absent, Name set to TestEnvironmentVariable, and Path set to $false, the resource removes the environment variable called TestEnvironmentVariable if it exists.
🌐
GARYTOWN
garytown.com › edit-add-remove-system-path-variable-via-powershell
Edit (Add / Remove) System Path Variable via PowerShell – GARYTOWN ConfigMgr Blog
August 22, 2019 - Grabs Current System Environment Path Variable and Places into a PowerShell Variable “Environment” · Checks for “rules” of items you want to delete, then deletes them from the PowerShell Variable
🌐
Microsoft Learn
learn.microsoft.com › en-us › powershell › module › microsoft.powershell.utility › remove-variable
Remove-Variable (Microsoft.PowerShell.Utility) - PowerShell | Microsoft Learn
PowerShell includes the following aliases for Remove-Variable: ... Changes affect only the current scope, such as a session. To delete a variable from all sessions, add a Remove-Variable command to your PowerShell profile.
🌐
GitHub
github.com › powershell › powershell › issues › 27414
[Environment]::SetEnvironmentVariable(..., $null, 'User') does not fully remove user environment variables since PowerShell 7.5 · Issue #27414 · PowerShell/PowerShell
1 month ago - The environment variable should be completely removed. No variable named TEST_ENV_VAR should remain. This is the behavior in PowerShell 7.4.14. The variable name still exists, but its value becomes empty/null. ... The registry entry is not fully deleted.
Author   PowerShell
🌐
SS64
ss64.com › vb › envrm.html
Remove environment variable - VBScript - SS64.com
Syntax objShell.Environment(strType).Remove(strName) Key objShell A WScript.Shell object strString The environment variable to be removed strType one of "System" (HKLM), "User" (HKCU), "Volatile" or "Process" ' Delete the LAST_LOGIN_DATE user environment variable Set objShell = Wscript.CreateObject("Wscript.Shell") objShell.Environment("USER").Remove("LAST_LOGIN_DATE")
Top answer
1 of 6
1

One thing I find useful, from the command line, is to se Get-Chiditem to ensure you have the files then pipe the command to Remove-Item. So

Get-ChildItem -path 

If that shows the right files - then just up arrow, click end and add:

Get-ChildItem -path  | Remove-Item -force

This way, you work out that you had the path wrong as pointed out by @francishagyard2 ​.

2 of 6
9

Background: I want a script to run for new users and only once so I made a very short cmd the starts a powershell script that creates a shortcut that points to a cmd that deletes 3 folders if there is no flag and then creates a flag and deletes the shortcut that started it.

The powershell script creates a shortcut in:

$Shortcut = $WshShell.CreateShortcut("C:\Users\Default\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\delete firefox profile.lnk")

Then when a new user logs in that becomes a shortcut in:

"$Env:AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\delete firefox profile.lnk"

I logged in as a test user and I’m looking at the file as I type but when I try to delete it in cmd or powershell I’m told that the file does not exist.

I can delete it if I reference the explicit location of the file:

Remove-Item "C:\Users\testdept\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\delete firefox profile.lnk"

but if I use and environment variable I get the following:

Remove-Item "$Env:AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\delete firefox profile.lnk"
Remove-Item : Cannot find path 'C:\Users\testdept\AppData\Roaming\Roaming\Microsoft\Windows\Start
Menu\Programs\Startup\delete firefox profile.lnk' because it does not exist.
At line:1 char:1
+ Remove-Item "$Env:AppData\Roaming\Microsoft\Windows\Start Menu\Progra ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\testde...fox profile.lnk:String) [Remove-Item], ItemNotFoundEx
   ception
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand

I get the same thing in cmd when using %userprofile% which translates to the explicit path

del "%userprofile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Start-up\delete firefox profile.lnk" /q/s

gets me

del "C:\Users\testdept\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Start-up\deletefirefoxprofile.lnk" /q/s
The system cannot find the file specified.

and since I want to do this for new users I need to use variables

🌐
Local Host
locall.host › home › powershell › mastering variable removal: a comprehensive guide on how to delete a powershell variable
Mastering Variable Removal: A Comprehensive Guide on How to Delete a PowerShell Variable
August 10, 2023 - To view a list of all accessible variables, simply type the following command in the PowerShell console: ... This command will generate an output listing every single variable present in your session. From here, you can discern which ones require deletion, paving the way for optimal management and organization.
🌐
YouTube
youtube.com › watch
PowerShell Quick Tips : Environment Variables
Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.
🌐
PowerShell Gallery
powershellgallery.com › packages › pwsh-environment › 1.0.1 › Content › public\Remove-EnvironmentVariable.ps1
PowerShell Gallery | public/Remove-EnvironmentVariable.ps1 1.0.1
pwsh-environment · 1.0.1 · public/Remove-EnvironmentVariable.ps1 · Contact Us · Terms of Use · Gallery Status · Feedback · © 2026 Microsoft Corporation