Creates or sets an environment variable.
Set-EnvironmentVariable [-Name] <String> [-Value] <String> [-ForProcess] [-ForUser] [-ForComputer] [-WhatIf] [-Confirm] [<CommonParameters>]
Uses the .NET Environment class to create or set an environment variable in the Process, User, or Machine 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.
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 | |
ForProcess | SwitchParameter | Sets the environment variable for the current process. |
false | false | False |
ForUser | SwitchParameter | Sets the environment variable for the current user. |
false | false | False |
ForComputer | SwitchParameter | Sets the environment variable for the current computer. |
false | false | 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' -ForProcess
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' -ForComputer
Creates the MyEnvironmentVariable
with an initial value of Value1
in the machine scope, i.e. the variable is accessible in all newly launched processes.