Creates or sets an environment variable.
Set-EnvironmentVariable [-Name] <String> [-Value] <String> [-Scope] {Process | User | Machine} [-WhatIf] [-Confirm] [<CommonParameters>]
Uses the .NET Environment class to create or set an environment variable in 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 name of environment variable to add/set. | true | false | |
Value | String | The environment variable's value. | 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 . |
Set-EnvironmentVariable -Name 'MyEnvironmentVariable' -Value 'Value1' -Scope Process
Creates the MyEnvironmentVariable
with an initial value of Value1
in the process scope, i.e. the variable is only accessible in the current process.
Set-EnvironmentVariable -Name 'MyEnvironmentVariable' -Value 'Value1' -Scope Machine
Creates the MyEnvironmentVariable
with an initial value of Value1
in the machine scope, i.e. the variable is accessible in all newly launched processes.