Removes an environment variable.
Remove-EnvironmentVariable [-Name] <String> [-Scope] {Process | User | Machine} [-WhatIf] [-Confirm] [<CommonParameters>]
Uses the .NET Environment class to remove an environment variable from the Process, User, or Machine scopes.
The -Scope
parameter should be a value from the EnvironmentVariableTarget enumeration, which is currently:
Process
User
Machine
You can see the values by running:
[Enum]::GetValues([EnvironmentVariableTarget])
Changes to environment variables in the User and Machine scope are not picked up by running processes. Any running processes that use this environment variable should be restarted.
Name | Type | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
Name | String | The environment variable to remove. | true | false | |
Scope | EnvironmentVariableTarget | true | false | ||
WhatIf | SwitchParameter | false | false | ||
Confirm | SwitchParameter | false | false | ||
CommonParameters | This cmdlet supports common parameters. For more information type Get-Help about_CommonParameters . |
Remove-EnvironmentVariable -Name 'MyEnvironmentVariable' -Scope Process
Removes the MyEnvironmentVariable
from the process scope.