Remove-EnvironmentVariable

Removes an environment variable.

Syntax

Remove-EnvironmentVariable [-Name] <String> [-Scope] {Process | User | Machine} [-WhatIf] [-Confirm] [<CommonParameters>]

Description

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:

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.

Related Commands

Parameters

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.

EXAMPLE 1

Remove-EnvironmentVariable -Name 'MyEnvironmentVariable' -Scope Process

Removes the MyEnvironmentVariable from the process scope.