< Back

Remove-CEnvironmentVariable

Sun Jan 12, 2020 10:51 pm

NAME Remove-CEnvironmentVariable



SYNOPSIS

Removes an environment variable.





SYNTAX

Remove-CEnvironmentVariable -Name <String> [-ForComputer] [-ForUser] [-ForProcess] [-Force] [-WhatIf] [-Confirm]

[<CommonParameters>]



Remove-CEnvironmentVariable -Name <String> -ForUser -Credential <PSCredential> [-WhatIf] [-Confirm]

[<CommonParameters>]





DESCRIPTION

Uses the .NET [Environment class](http://msdn.microsoft.com/en-us/library/z8te35sa) to remove an environment

variable from the Process, User, or Computer scopes.



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.



Normally, you have to restart your PowerShell session/process to no longer see the variable in the `env:` drive.

Use the `-Force` switch to also remove the variable from the `env:` drive. This functionality was added in Carbon

2.3.0.



Beginning with Carbon 2.3.0, you can set an environment variable for a specific user by specifying the `-ForUser`

switch and passing the user's credentials with the `-Credential` parameter. This runs a separate PowerShell

process as that user to remove the variable.



Beginning in Carbon 2.3.0, you can specify multiple scopes from which to remove an environment variable. In

previous versions, you could only remove from one scope.





PARAMETERS

-Name <String>

The environment variable to remove.



Required? true

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-ForComputer [<SwitchParameter>]

Removes the environment variable for the current computer.



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-ForUser [<SwitchParameter>]

Removes the environment variable for the current user.



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-ForProcess [<SwitchParameter>]

Removes the environment variable for the current process.



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-Force [<SwitchParameter>]

Remove the variable from the current PowerShell session's `env:` drive, too. Normally, you have to restart

your session to no longer see the variable in the `env:` drive.



This parameter was added in Carbon 2.3.0.



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-Credential <PSCredential>

Remove an environment variable for a specific user.



Required? true

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-WhatIf [<SwitchParameter>]



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Confirm [<SwitchParameter>]



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>Remove-CEnvironmentVariable -Name 'MyEnvironmentVariable' -ForProcess



Removes the `MyEnvironmentVariable` from the process scope.









-------------------------- EXAMPLE 2 --------------------------



PS C:\\>Remove-CEnvironmentVariable -Name 'SomeUsersVariable' -ForUser -Credential $credential



Demonstrates that you can remove another user's user-level environment variable by passing its credentials to the

`Credential` parameter. This runs a separate PowerShell process as that user to remove the variable.











RELATED LINKS

Carbon_EnvironmentVariable

Set-CEnvironmentVariable

http://msdn.microsoft.com/en-us/library/z8te35sa