Updates from: 04/02/2022 01:57:56
Service Microsoft Docs article Related commit history on GitHub Change details
Microsoft.PowerShell.Core About Environment Variables (5.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/5.1/Microsoft.PowerShell.Core/About/about_Environment_Variables.md
---
-description: Describes how to access Windows environment variables in PowerShell.
+description: Describes how to access and manage environment variables in PowerShell.
Locale: en-US Previously updated : 11/15/2021 Last updated : 03/31/2022 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-5.1&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about Environment Variables
Title: about Environment Variables
# about_Environment_Variables ## Short description
-Describes how to access Windows environment variables in PowerShell.
+Describes how to access and manage environment variables in PowerShell.
## Long description
-Environment variables store information about the operating system
-environment. This information includes details such as the operating system
-path, the number of processors used by the operating system, and the location
-of temporary folders.
-
-The environment variables store data that is used by the operating system and
+Environment variables store data that is used by the operating system and
other programs. For example, the `WINDIR` environment variable contains the location of the Windows installation directory. Programs can query the value of this variable to determine where Windows operating system files are located. PowerShell can access and manage environment variables in any of the supported
-operating system platforms. The PowerShell environment provider simplifies this
-process by making it easy to view and change environment variables.
+operating system platforms. The PowerShell environment provider lets you get,
+add, change, clear, and delete environment variables in the current console.
-Environment variables, unlike other types of variables in PowerShell, are
+Environment variables, unlike other types of variables in PowerShell, are always
+stored as a string and can't be empty. Also unlike other variables, they are
inherited by child processes, such as local background jobs and the sessions in which module members run. This makes environment variables well suited to storing values that are needed in both parent and child processes.
-## Using and changing environment variables
- On Windows, environment variables can be defined in three scopes: - Machine (or System) scope
process, or PowerShell session. This list of variables is inherited from the
parent process and is constructed from the variables in the _Machine_ and _User_ scopes.
-You can display and change the values of environment variables without using a
-cmdlet by using a variable syntax with the environment provider. To display the
-value of an environment variable, use the following syntax:
+When you change environment variables in PowerShell, the change affects only
+the current session. This behavior resembles the behavior of the `Set` command
+in the Windows Command Shell and the `Setenv` command in UNIX-based
+environments. To change values in the Machine or User scopes, you must use the
+methods of the **System.Environment** class.
+
+To make changes to Machine-scoped variables, you must also have permission. If
+you try to change a value without sufficient permission, the command fails and
+PowerShell displays an error.
+
+PowerShell provides several different methods for using and managing environment
+variables.
+
+- The variable syntax
+- The Environment provider and Item cmdlets
+- The .NET **System.Environment** class
+
+## Using the variable syntax
+
+You can display and change the values of environment variables with the
+following syntax:
``` $Env:<variable-name> ```
-For example, to display the value of the `WINDIR` environment variable, type
-the following command at the PowerShell command prompt:
+For example, to display the value of the `WINDIR` environment variable:
```powershell $Env:windir ```
+```Output
+C:\Windows
+```
+ In this syntax, the dollar sign (`$`) indicates a variable, and the drive name (`Env:`) indicates an environment variable followed by the variable name (`windir`).
-When you change environment variables in PowerShell, the change affects only
-the current session. This behavior resembles the behavior of the `Set` command
-in the Windows Command Shell and the `Setenv` command in UNIX-based
-environments. To change values in the Machine or User scopes, you must use the
-methods of the **System.Environment** class.
-
-To make changes to Machine-scoped variables, you must also have permission. If
-you try to change a value without sufficient permission, the command fails and
-PowerShell displays an error.
-
-You can change the values of variables without using a cmdlet using the
-following syntax:
+You can create and update the value of environment variables with the following
+syntax:
```powershell $Env:<variable-name> = "<new-value>" ```
-For example, to append `;c:\temp` to the value of the `Path` environment
-variable, use the following syntax:
+For example, to create the `Foo` environment variable:
```powershell
-$Env:Path += ";c:\temp"
+$Env:Foo = 'An example'
```
-You can also use the Item cmdlets, such as `Set-Item`, `Remove-Item`, and
-`Copy-Item` to change the values of environment variables. For example, to use
-the `Set-Item` cmdlet to append `;c:\temp` to the value of the `Path`
-environment variable, use the following syntax:
+Because environment variables are always strings, you can use them like any
+other variable containing a string. For example:
```powershell
-Remove-Item -Path Env:Path
+"The 'Foo' environment variable is set to: $Env:Foo"
+$Env:Foo += '!'
+$Env:Foo
+```
+
+```Output
+The 'Foo' environment variable is set to: An example
+
+An example!
```
-In this command, the variable is cleared. Note that the environment
-variable is referenced as an Item path and `$` is not used.
+Because an environment variable can't be an empty string, setting one to `$null`
+or an empty string removes it. For example:
```powershell
-Set-Item -Path Env:Path -Value ($Env:Path + ";C:\Temp")
+$Env:Foo = ''
+$Env:Foo | Get-Member -MemberType Properties
```
-In this command, the value is enclosed in parentheses so that it is
-interpreted as a unit.
+```Output
+Get-Member : You must specify an object for the Get-Member cmdlet.
+At line:1 char:12
++ $env:foo | Get-Member++ ~~~~~~~~~~
+ + CategoryInfo : CloseError: (:) [Get-Member], InvalidOperationException
+ + FullyQualifiedErrorId : NoObjectInGetMember,Microsoft.PowerShell.Commands.GetMemberCommand
+```
-## Managing environment variables
+`Get-Member` returned an error because the environment variable was removed. You
+can see that it does not return an error when you use it on an empty string:
-PowerShell provides several different methods for managing environment
-variables.
+```powershell
+'' | Get-Member -MemberType Properties
+```
-- The Environment provider drive-- The Item cmdlets-- The .NET **System.Environment** class-- On Windows, the System Control Panel
+```Output
+ TypeName: System.String
-### Using the Environment provider
+Name MemberType Definition
+---- ---------- ----------
+Length Property int Length {get;}
+```
-Each environment variable is represented by an instance of the
-**System.Collections.DictionaryEntry** class. In each **DictionaryEntry**
-object, the name of the environment variable is the dictionary key. The value
-of the variable is the dictionary value.
+For more information about variables in PowerShell, see
+[about_Variables](about_variables.md).
-To display the properties and methods of the object that represents an
-environment variable in PowerShell, use the `Get-Member` cmdlet. For example,
-to display the methods and properties of all the objects in the `Env:` drive,
-type:
+## Using the Environment provider and Item cmdlets
-```powershell
-Get-Item -Path Env:* | Get-Member
-```
+PowerShell's **Environment** provider gives you an interface for interacting
+with environment variables in a format that resembles a file system drive. It
+lets you get, add, change, clear, and delete environment variables and values in
+PowerShell.
-The PowerShell Environment provider lets you access environment variables in a
-PowerShell drive (the `Env:` drive). This drive looks much like a file system
-drive. To go to the `Env:` drive, type:
+For example, to create the `Foo` environment variable with a value of `Bar`:
```powershell
-Set-Location Env:
+New-Item -Path Env:\Foo -Value 'Bar'
```
-Use the Content cmdlets to get or set the values of an environment variable.
+```Output
+Name Value
+---- -----
+Foo Bar
+```
+
+You can also copy the environment variable with `Copy-Item`, set the value of an
+environment variable with `Set-Item`, list environment variables with
+`Get-Item`, and delete the environment variable with `Remove-Item`.
```powershell
-PS Env:\> Set-Content -Path Test -Value 'Test value'
-PS Env:\> Get-Content -Path Test
-Test value
+Copy-Item -Path Env:\Foo -Destination Env:\Foo2 -PassThru
+Set-Item -Path Env:\Foo2 -Value 'BAR'
+Get-Item -Path Env:\Foo*
+Remove-Item -Path Env:\Foo* -Verbose
```
-You can view the environment variables in the `Env:` drive from any other
-PowerShell drive, and you can go into the `Env:` drive to view and change the
-environment variables.
+```Output
+Name Value
+---- -----
+Foo2 Bar
-### Using Item cmdlets
+Name Value
+---- -----
+Foo2 BAR
+Foo Bar
-When you refer to an environment variable, type the `Env:` drive name followed
-by the name of the variable. For example, to display the value of the
-`COMPUTERNAME` environment variable, type:
-
-```powershell
-Get-ChildItem Env:Computername
+VERBOSE: Performing the operation "Remove Item" on target "Item: Foo2".
+VERBOSE: Performing the operation "Remove Item" on target "Item: Foo".
```
-To display the values of all the environment variables, type:
+For more information on using the **Environment** provider to manage environment
+variables, see [about_Environment_Provider](about_Environment_Provider.md).
-```powershell
-Get-ChildItem Env:
-```
+## Using the System.Environment methods
-Because environment variables do not have child items, the output of `Get-Item`
-and `Get-ChildItem` is the same.
+The **System.Environment** class provides the **GetEnvironmentVariable** and
+**SetEnvironmentVariable** methods to get and modify environment variables.
-By default, PowerShell displays the environment variables in the order in which
-it retrieves them. To sort the list of environment variables by variable name,
-pipe the output of a `Get-ChildItem` command to the `Sort-Object` cmdlet. For
-example, from any PowerShell drive, type:
+The following example creates a new environment variable, `Foo`, with a value of
+`Bar` and then returns its value.
```powershell
-Get-ChildItem Env: | Sort Name
+[Environment]::SetEnvironmentVariable('Foo','Bar')
+[Environment]::GetEnvironmentVariable('Foo')
+```
+
+```Output
+Bar
```
-You can also go into the `Env:` drive by using the `Set-Location` cmdlet:
+You can remove an environment variable with the **SetEnvironmentVariable**
+method by specifying an empty string for the variable's value. For example,
+to remove the `Foo` environment variable:
```powershell
-Set-Location Env:
+[Environment]::SetEnvironmentVariable('Foo','')
+[Environment]::GetEnvironmentVariable('Foo')
```
-When you are in the `Env:` drive, you can omit the `Env:` drive name from the
-path. For example, to display all the environment variables, type:
+```Output
-```powershell
-PS Env:\> Get-ChildItem
```
-To display the value of the `COMPUTERNAME` variable from within the `Env:`
-drive, type:
+For more information about the methods of the **System.Environment** class, see
+[Environment Methods](/dotnet/api/system.environment).
+
+## Saving changes to environment variables
+
+On Windows, there are three methods for making a persistent change to an
+environment variable: setting them in your profile, using the
+**SetEnvironmentVariable** method, and using the System Control Panel.
+
+### Saving environment variables in your profile
+
+Any environment variable you add or change in your PowerShell profile is
+available in any session that loads your profile. This method works for any
+version of PowerShell on any supported platform.
+
+For example, to create the `CompanyUri` environment variable and update the
+`Path` environment variable to include the `C:\Tools` folder, add the following
+lines to your PowerShell profile:
```powershell
-PS Env:\> Get-ChildItem ComputerName
+$Env:CompanyUri = 'https://internal.contoso.com'
+$Env:Path += ';C:\Tools'
```
-### Saving changes to environment variables
+You can get the path to your PowerShell profile with the `$PROFILE` automatic
+variable. For more information on profiles, see
+[about_Profiles](about_profiles.md).
-To make a persistent change to an environment variable on Windows, use the
-System Control Panel. Select **Advanced System Settings**. On the **Advanced**
-tab, click **Environment Variable...**. You can add or edit existing
-environment variables in the **User** and **System** (Machine) scopes. Windows
-writes these values to the Registry so that they persist across sessions and
-system restarts.
+### Saving environment variables with SetEnvironmentVariable
-Alternately, you can add or change environment variables in your PowerShell
-profile. This method works for any version of PowerShell on any supported
-platform.
+On Windows, you can specify a scope for the **SetEnvironmentVariable** method as
+the third parameter to set the environment variable in that scope. The machine
+and user scopes both persist outside of the current process, allowing you to
+save a new or changed environment variable.
-### Using System.Environment methods
+For example, to save a new environment variable `Foo` with the value `Bar`to the
+machine scope:
-The **System.Environment** class provides **GetEnvironmentVariable** and
-**SetEnvironmentVariable** methods that allow you to specify the scope of the
-variable.
+```powershell
+[Environment]::SetEnvironmentVariable('Foo', 'Bar', 'Machine')
+```
-The following example uses the **GetEnvironmentVariable** method to get the
-machine setting of `PSModulePath` and the **SetEnvironmentVariable** method
-to add the `C:\Program Files\Fabrikam\Modules` path to the value.
+You can delete an environment variable from the user or machine scope by setting
+the variable's value to an empty string.
```powershell
-$path = [Environment]::GetEnvironmentVariable('PSModulePath', 'Machine')
-$newpath = $path + ';C:\Program Files\Fabrikam\Modules'
-[Environment]::SetEnvironmentVariable("PSModulePath", $newpath, 'Machine')
+[Environment]::SetEnvironmentVariable('Foo', '', 'Machine')
```
-For more information about the methods of the **System.Environment** class, see
-[Environment Methods](/dotnet/api/system.environment).
+### Saving environment variables with the System Control Panel
+
+In the System Control Panel, you can add or edit existing environment variables
+in the **User** and **System** (Machine) scopes. Windows writes these values to
+the Registry so that they persist across sessions and system restarts.
+
+To make a persistent change to an environment variable on Windows using the
+System Control Panel:
+
+1. Open the System Control Panel.
+1. Select **System**.
+1. Select **Advanced System Settings**.
+1. Go to the **Advanced** tab.
+1. Select **Environment Variables...**.
+1. Make your changes.
## PowerShell's environment variables
The environment variables that store preferences include:
command and is written on a background thread sometime after a module is imported.
- Default location of the cache is:
+ The default location of the cache is:
- `$env:LOCALAPPDATA\Microsoft\Windows\PowerShell`
- The default filename for the cache is `ModuleAnalysisCache`. To change the
- default location of the cache, set the environment variable before starting
- PowerShell. Changes to this environment variable only affect child processes.
- The value should name a full path (including filename) that PowerShell has
- permission to create and write files.
+ The default filename for the cache is `ModuleAnalysisCache`.
> [!NOTE]
- > If command discovery isn't working correctly, for example Intellisense
+ > If command discovery isn't working correctly, for example IntelliSense
> shows commands that don't exist, you can delete the cache file. The cache > is recreated the next time you start PowerShell.
- To disable the file cache, set this value to an invalid location, for
- example:
+ To change the default location of the cache, set the environment variable
+ before starting PowerShell. Changes to this environment variable only affect
+ child processes. The value should name a full path (including filename) that
+ PowerShell has permission to create and write files.
+
+ To disable the file cache, set this value to an invalid location, for example:
```powershell # `NUL` here is a special device on Windows that cannot be written to
The environment variables that store preferences include:
## See also - [about_Environment_Provider](about_Environment_Provider.md)-- [about_Modules](about_Modules.md)
+- [about_Profiles](about_profiles.md)
+- [about_Variables](about_variables.md)
+- [Environment Methods](/dotnet/api/system.environment)
Microsoft.PowerShell.Core About Environment Variables (7.0) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.0/Microsoft.PowerShell.Core/About/about_Environment_Variables.md
---
-description: Describes how to access Windows environment variables in PowerShell.
+description: Describes how to access and manage environment variables in PowerShell.
Locale: en-US Previously updated : 11/15/2021 Last updated : 03/31/2022 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-7&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about Environment Variables
Title: about Environment Variables
# about_Environment_Variables ## Short description
-Describes how to access Windows environment variables in PowerShell.
+Describes how to access and manage environment variables in PowerShell.
## Long description
-Environment variables store information about the operating system
-environment. This information includes details such as the operating system
-path, the number of processors used by the operating system, and the location
-of temporary folders.
-
-The environment variables store data that is used by the operating system and
+Environment variables store data that is used by the operating system and
other programs. For example, the `WINDIR` environment variable contains the location of the Windows installation directory. Programs can query the value of this variable to determine where Windows operating system files are located. PowerShell can access and manage environment variables in any of the supported
-operating system platforms. The PowerShell environment provider simplifies this
-process by making it easy to view and change environment variables.
+operating system platforms. The PowerShell environment provider lets you get,
+add, change, clear, and delete environment variables in the current console.
-Environment variables, unlike other types of variables in PowerShell, are
+Environment variables, unlike other types of variables in PowerShell, are always
+stored as a string and can't be empty. Also unlike other variables, they are
inherited by child processes, such as local background jobs and the sessions in which module members run. This makes environment variables well suited to storing values that are needed in both parent and child processes.
-## Using and changing environment variables
- On Windows, environment variables can be defined in three scopes: - Machine (or System) scope
On Windows, environment variables can be defined in three scopes:
The _Process_ scope contains the environment variables available in the current process, or PowerShell session. This list of variables is inherited from the parent process and is constructed from the variables in the _Machine_ and
-_User_ scopes. Unix-based platforms only have the _Process_ scope.
+_User_ scopes.
+
+When you change environment variables in PowerShell, the change affects only
+the current session. This behavior resembles the behavior of the `Set` command
+in the Windows Command Shell and the `Setenv` command in UNIX-based
+environments. To change values in the Machine or User scopes, you must use the
+methods of the **System.Environment** class.
+
+To make changes to Machine-scoped variables, you must also have permission. If
+you try to change a value without sufficient permission, the command fails and
+PowerShell displays an error.
+
+PowerShell provides several different methods for using and managing environment
+variables.
-You can display and change the values of environment variables without using a
-cmdlet by using a variable syntax with the environment provider. To display the
-value of an environment variable, use the following syntax:
+- The variable syntax
+- The Environment provider and Item cmdlets
+- The .NET **System.Environment** class
+
+## Using the variable syntax
+
+You can display and change the values of environment variables with the
+following syntax:
``` $Env:<variable-name> ```
-For example, to display the value of the `WINDIR` environment variable, type
-the following command at the PowerShell command prompt:
+For example, to display the value of the `WINDIR` environment variable:
```powershell $Env:windir ```
+```Output
+C:\Windows
+```
+ In this syntax, the dollar sign (`$`) indicates a variable, and the drive name (`Env:`) indicates an environment variable followed by the variable name (`windir`).
-When you change environment variables in PowerShell, the change affects only
-the current session. This behavior resembles the behavior of the `Set` command
-in the Windows Command Shell and the `Setenv` command in UNIX-based
-environments. To change values in the Machine or User scopes, you must use the
-methods of the **System.Environment** class.
-
-To make changes to Machine-scoped variables, you must also have permission. If
-you try to change a value without sufficient permission, the command fails and
-PowerShell displays an error.
-
-You can change the values of variables without using a cmdlet using the
-following syntax:
+You can create and update the value of environment variables with the following
+syntax:
```powershell $Env:<variable-name> = "<new-value>" ```
-For example, to append `;c:\temp` to the value of the `Path` environment
-variable, use the following syntax:
+For example, to create the `Foo` environment variable:
```powershell
-$Env:Path += ";c:\temp"
+$Env:Foo = 'An example'
```
-On Linux or macOS, the colon (`:`) in the command separates the new path from
-the path that precedes it in the list.
+Because environment variables are always strings, you can use them like any
+other variable containing a string. For example:
```powershell
-$Env:PATH += ":/usr/local/temp"
+"The 'Foo' environment variable is set to: $Env:Foo"
+$Env:Foo += '!'
+$Env:Foo
```
-You can also use the Item cmdlets, such as `Set-Item`, `Remove-Item`, and
-`Copy-Item` to change the values of environment variables. For example, to use
-the `Set-Item` cmdlet to append `;c:\temp` to the value of the `Path`
-environment variable, use the following syntax:
+```Output
+The 'Foo' environment variable is set to: An example
-```powershell
-Remove-Item -Path Env:Path
+An example!
```
-In this command, the variable is cleared. Note that the environment
-variable is referenced as an Item path and `$` is not used.
+Because an environment variable can't be an empty string, setting one to `$null`
+or an empty string removes it. For example:
```powershell
-Set-Item -Path Env:Path -Value ($Env:Path + ";C:\Temp")
+$Env:Foo = ''
+$Env:Foo | Get-Member -MemberType Properties
```
-In this command, the value is enclosed in parentheses so that it is
-interpreted as a unit.
+```Output
+Get-Member : You must specify an object for the Get-Member cmdlet.
+At line:1 char:12
++ $env:foo | Get-Member++ ~~~~~~~~~~
+ + CategoryInfo : CloseError: (:) [Get-Member], InvalidOperationException
+ + FullyQualifiedErrorId : NoObjectInGetMember,Microsoft.PowerShell.Commands.GetMemberCommand
+```
-## Managing environment variables
+`Get-Member` returned an error because the environment variable was removed. You
+can see that it does not return an error when you use it on an empty string:
-PowerShell provides several different methods for managing environment
-variables.
+```powershell
+'' | Get-Member -MemberType Properties
+```
-- The Environment provider drive-- The Item cmdlets-- The .NET **System.Environment** class-- On Windows, the System Control Panel
+```Output
+ TypeName: System.String
-### Using the Environment provider
+Name MemberType Definition
+---- ---------- ----------
+Length Property int Length {get;}
+```
-Each environment variable is represented by an instance of the
-**System.Collections.DictionaryEntry** class. In each **DictionaryEntry**
-object, the name of the environment variable is the dictionary key. The value
-of the variable is the dictionary value.
+For more information about variables in PowerShell, see
+[about_Variables](about_variables.md).
-To display the properties and methods of the object that represents an
-environment variable in PowerShell, use the `Get-Member` cmdlet. For example,
-to display the methods and properties of all the objects in the `Env:` drive,
-type:
+## Using the Environment provider and Item cmdlets
-```powershell
-Get-Item -Path Env:* | Get-Member
-```
+PowerShell's **Environment** provider gives you an interface for interacting
+with environment variables in a format that resembles a file system drive. It
+lets you get, add, change, clear, and delete environment variables and values in
+PowerShell.
-The PowerShell Environment provider lets you access environment variables in a
-PowerShell drive (the `Env:` drive). This drive looks much like a file system
-drive. To go to the `Env:` drive, type:
+For example, to create the `Foo` environment variable with a value of `Bar`:
```powershell
-Set-Location Env:
+New-Item -Path Env:\Foo -Value 'Bar'
```
-Use the Content cmdlets to get or set the values of an environment variable.
+```Output
+Name Value
+---- -----
+Foo Bar
+```
+
+You can also copy the environment variable with `Copy-Item`, set the value of an
+environment variable with `Set-Item`, list environment variables with
+`Get-Item`, and delete the environment variable with `Remove-Item`.
```powershell
-PS Env:\> Set-Content -Path Test -Value 'Test value'
-PS Env:\> Get-Content -Path Test
-Test value
+Copy-Item -Path Env:\Foo -Destination Env:\Foo2 -PassThru
+Set-Item -Path Env:\Foo2 -Value 'BAR'
+Get-Item -Path Env:\Foo*
+Remove-Item -Path Env:\Foo* -Verbose
```
-You can view the environment variables in the `Env:` drive from any other
-PowerShell drive, and you can go into the `Env:` drive to view and change the
-environment variables.
-
-### Using Item cmdlets
+```Output
+Name Value
+---- -----
+Foo2 Bar
-When you refer to an environment variable, type the `Env:` drive name followed
-by the name of the variable. For example, to display the value of the
-`COMPUTERNAME` environment variable, type:
+Name Value
+---- -----
+Foo2 BAR
+Foo Bar
-```powershell
-Get-ChildItem Env:Computername
+VERBOSE: Performing the operation "Remove Item" on target "Item: Foo2".
+VERBOSE: Performing the operation "Remove Item" on target "Item: Foo".
```
-To display the values of all the environment variables, type:
+For more information on using the **Environment** provider to manage environment
+variables, see [about_Environment_Provider](about_Environment_Provider.md).
-```powershell
-Get-ChildItem Env:
-```
+## Using the System.Environment methods
-Because environment variables do not have child items, the output of `Get-Item`
-and `Get-ChildItem` is the same.
+The **System.Environment** class provides the **GetEnvironmentVariable** and
+**SetEnvironmentVariable** methods to get and modify environment variables.
-By default, PowerShell displays the environment variables in the order in which
-it retrieves them. To sort the list of environment variables by variable name,
-pipe the output of a `Get-ChildItem` command to the `Sort-Object` cmdlet. For
-example, from any PowerShell drive, type:
+The following example creates a new environment variable, `Foo`, with a value of
+`Bar` and then returns its value.
```powershell
-Get-ChildItem Env: | Sort Name
+[Environment]::SetEnvironmentVariable('Foo','Bar')
+[Environment]::GetEnvironmentVariable('Foo')
+```
+
+```Output
+Bar
```
-You can also go into the `Env:` drive by using the `Set-Location` cmdlet:
+You can remove an environment variable with the **SetEnvironmentVariable**
+method by specifying an empty string for the variable's value. For example,
+to remove the `Foo` environment variable:
```powershell
-Set-Location Env:
+[Environment]::SetEnvironmentVariable('Foo','')
+[Environment]::GetEnvironmentVariable('Foo')
```
-When you are in the `Env:` drive, you can omit the `Env:` drive name from the
-path. For example, to display all the environment variables, type:
+```Output
-```powershell
-PS Env:\> Get-ChildItem
```
-To display the value of the `COMPUTERNAME` variable from within the `Env:`
-drive, type:
+For more information about the methods of the **System.Environment** class, see
+[Environment Methods](/dotnet/api/system.environment).
+
+## Saving changes to environment variables
+
+On Windows, there are three methods for making a persistent change to an
+environment variable: setting them in your profile, using the
+**SetEnvironmentVariable** method, and using the System Control Panel.
+
+### Saving environment variables in your profile
+
+Any environment variable you add or change in your PowerShell profile is
+available in any session that loads your profile. This method works for any
+version of PowerShell on any supported platform.
+
+For example, to create the `CompanyUri` environment variable and update the
+`Path` environment variable to include the `C:\Tools` folder, add the following
+lines to your PowerShell profile:
```powershell
-PS Env:\> Get-ChildItem ComputerName
+$Env:CompanyUri = 'https://internal.contoso.com'
+$Env:Path += ';C:\Tools'
```
-### Saving changes to environment variables
+> [!NOTE]
+> On Linux or macOS, the colon (`:`) is used instead of a semi-colon(`;`) to
+> separate a new path from the path that precedes it in the list.
+
+You can get the path to your PowerShell profile with the `$PROFILE` automatic
+variable. For more information on profiles, see
+[about_Profiles](about_profiles.md).
-To make a persistent change to an environment variable on Windows, use the
-System Control Panel. Select **Advanced System Settings**. On the **Advanced**
-tab, click **Environment Variable...**. You can add or edit existing
-environment variables in the **User** and **System** (Machine) scopes. Windows
-writes these values to the Registry so that they persist across sessions and
-system restarts.
+### Saving environment variables with SetEnvironmentVariable
-Alternately, you can add or change environment variables in your PowerShell
-profile. This method works for any version of PowerShell on any supported
-platform.
+On Windows, you can specify a scope for the **SetEnvironmentVariable** method as
+the third parameter to set the environment variable in that scope. The machine
+and user scopes both persist outside of the current process, allowing you to
+save a new or changed environment variable.
-### Using System.Environment methods
+For example, to save a new environment variable `Foo` with the value `Bar`to the
+machine scope:
-The **System.Environment** class provides **GetEnvironmentVariable** and
-**SetEnvironmentVariable** methods that allow you to specify the scope of the
-variable.
+```powershell
+[Environment]::SetEnvironmentVariable('Foo', 'Bar', 'Machine')
+```
-The following example uses the **GetEnvironmentVariable** method to get the
-machine setting of `PSModulePath` and the **SetEnvironmentVariable** method
-to add the `C:\Program Files\Fabrikam\Modules` path to the value.
+You can delete an environment variable from the user or machine scope by setting
+the variable's value to an empty string.
```powershell
-$path = [Environment]::GetEnvironmentVariable('PSModulePath', 'Machine')
-$newpath = $path + ';C:\Program Files\Fabrikam\Modules'
-[Environment]::SetEnvironmentVariable("PSModulePath", $newpath, 'Machine')
+[Environment]::SetEnvironmentVariable('Foo', '', 'Machine')
```
-For more information about the methods of the **System.Environment** class, see
-[Environment Methods](/dotnet/api/system.environment).
+### Saving environment variables with the System Control Panel
+
+In the System Control Panel, you can add or edit existing environment variables
+in the **User** and **System** (Machine) scopes. Windows writes these values to
+the Registry so that they persist across sessions and system restarts.
+
+To make a persistent change to an environment variable on Windows using the
+System Control Panel:
+
+1. Open the System Control Panel.
+1. Select **System**.
+1. Select **Advanced System Settings**.
+1. Go to the **Advanced** tab.
+1. Select **Environment Variables...**.
+1. Make your changes.
## PowerShell's environment variables
The environment variables that store preferences include:
command and is written on a background thread sometime after a module is imported.
- Default location of the cache is:
+ The default location of the cache is:
- Windows PowerShell 5.1: `$env:LOCALAPPDATA\Microsoft\Windows\PowerShell` - PowerShell 6.0 and higher: `$env:LOCALAPPDATA\Microsoft\PowerShell`
The environment variables that store preferences include:
To change the default location of the cache, set the environment variable before starting PowerShell. Changes to this environment variable only affect
- child processes. The value should name a full path (including filename)
- that PowerShell has permission to create and write files.
+ child processes. The value should name a full path (including filename) that
+ PowerShell has permission to create and write files.
- To disable the file cache, set this value to an invalid location, for
- example:
+ To disable the file cache, set this value to an invalid location, for example:
```powershell # `NUL` here is a special device on Windows that cannot be written to,
The environment variables that store preferences include:
- **XDG_DATA_HOME** - **XDG_CACHE_HOME**
-### Terminal features
-
-Beginning in PowerShell 7.2, the following environment variables can be used to
-control the Virtual Terminal features like ANSI escape sequences that colorize
-output. Support for ANSI escape sequences can be turned off using the **TERM**
-or **NO_COLOR** environment variables.
--- **TERM**-
- The following values of `$env:TERM` change the behavior as follows:
-
- - `dumb` - sets `$Host.UI.SupportsVirtualTerminal = $false`
- - `xterm-mono` - sets `$PSStyle.OutputRendering = PlainText`
- - `xtermm` - sets `$PSStyle.OutputRendering = PlainText`
--- **NO_COLOR**-
- If `$env:NO_COLOR` exists, then `$PSStyle.OutputRendering` is set to
- **PlainText**. For more information about the **NO_COLOR** environment
- variable, see [https://no-color.org/](https://no-color.org/).
- ## See also - [about_Environment_Provider](about_Environment_Provider.md)-- [about_Modules](about_Modules.md)
+- [about_Profiles](about_profiles.md)
+- [about_Variables](about_variables.md)
+- [Environment Methods](/dotnet/api/system.environment)
[xdg-bds]: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
Microsoft.PowerShell.Core About Environment Variables (7.1) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.1/Microsoft.PowerShell.Core/About/about_Environment_Variables.md
---
-description: Describes how to access Windows environment variables in PowerShell.
+description: Describes how to access and manage environment variables in PowerShell.
Locale: en-US Previously updated : 11/15/2021 Last updated : 03/31/2022 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-7.1&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about Environment Variables
Title: about Environment Variables
# about_Environment_Variables ## Short description
-Describes how to access Windows environment variables in PowerShell.
+Describes how to access and manage environment variables in PowerShell.
## Long description
-Environment variables store information about the operating system
-environment. This information includes details such as the operating system
-path, the number of processors used by the operating system, and the location
-of temporary folders.
-
-The environment variables store data that is used by the operating system and
+Environment variables store data that is used by the operating system and
other programs. For example, the `WINDIR` environment variable contains the location of the Windows installation directory. Programs can query the value of this variable to determine where Windows operating system files are located. PowerShell can access and manage environment variables in any of the supported
-operating system platforms. The PowerShell environment provider simplifies this
-process by making it easy to view and change environment variables.
+operating system platforms. The PowerShell environment provider lets you get,
+add, change, clear, and delete environment variables in the current console.
-Environment variables, unlike other types of variables in PowerShell, are
+Environment variables, unlike other types of variables in PowerShell, are always
+stored as a string and can't be empty. Also unlike other variables, they are
inherited by child processes, such as local background jobs and the sessions in which module members run. This makes environment variables well suited to storing values that are needed in both parent and child processes.
-## Using and changing environment variables
- On Windows, environment variables can be defined in three scopes: - Machine (or System) scope
On Windows, environment variables can be defined in three scopes:
The _Process_ scope contains the environment variables available in the current process, or PowerShell session. This list of variables is inherited from the parent process and is constructed from the variables in the _Machine_ and
-_User_ scopes. Unix-based platforms only have the _Process_ scope.
+_User_ scopes.
+
+When you change environment variables in PowerShell, the change affects only
+the current session. This behavior resembles the behavior of the `Set` command
+in the Windows Command Shell and the `Setenv` command in UNIX-based
+environments. To change values in the Machine or User scopes, you must use the
+methods of the **System.Environment** class.
+
+To make changes to Machine-scoped variables, you must also have permission. If
+you try to change a value without sufficient permission, the command fails and
+PowerShell displays an error.
+
+PowerShell provides several different methods for using and managing environment
+variables.
-You can display and change the values of environment variables without using a
-cmdlet by using a variable syntax with the environment provider. To display the
-value of an environment variable, use the following syntax:
+- The variable syntax
+- The Environment provider and Item cmdlets
+- The .NET **System.Environment** class
+
+## Using the variable syntax
+
+You can display and change the values of environment variables with the
+following syntax:
``` $Env:<variable-name> ```
-For example, to display the value of the `WINDIR` environment variable, type
-the following command at the PowerShell command prompt:
+For example, to display the value of the `WINDIR` environment variable:
```powershell $Env:windir ```
+```Output
+C:\Windows
+```
+ In this syntax, the dollar sign (`$`) indicates a variable, and the drive name (`Env:`) indicates an environment variable followed by the variable name (`windir`).
-When you change environment variables in PowerShell, the change affects only
-the current session. This behavior resembles the behavior of the `Set` command
-in the Windows Command Shell and the `Setenv` command in UNIX-based
-environments. To change values in the Machine or User scopes, you must use the
-methods of the **System.Environment** class.
-
-To make changes to Machine-scoped variables, you must also have permission. If
-you try to change a value without sufficient permission, the command fails and
-PowerShell displays an error.
-
-You can change the values of variables without using a cmdlet using the
-following syntax:
+You can create and update the value of environment variables with the following
+syntax:
```powershell $Env:<variable-name> = "<new-value>" ```
-For example, to append `;c:\temp` to the value of the `Path` environment
-variable, use the following syntax:
+For example, to create the `Foo` environment variable:
```powershell
-$Env:Path += ";c:\temp"
+$Env:Foo = 'An example'
```
-On Linux or macOS, the colon (`:`) in the command separates the new path from
-the path that precedes it in the list.
+Because environment variables are always strings, you can use them like any
+other variable containing a string. For example:
```powershell
-$Env:PATH += ":/usr/local/temp"
+"The 'Foo' environment variable is set to: $Env:Foo"
+$Env:Foo += '!'
+$Env:Foo
```
-You can also use the Item cmdlets, such as `Set-Item`, `Remove-Item`, and
-`Copy-Item` to change the values of environment variables. For example, to use
-the `Set-Item` cmdlet to append `;c:\temp` to the value of the `Path`
-environment variable, use the following syntax:
+```Output
+The 'Foo' environment variable is set to: An example
-```powershell
-Remove-Item -Path Env:Path
+An example!
```
-In this command, the variable is cleared. Note that the environment
-variable is referenced as an Item path and `$` is not used.
+Because an environment variable can't be an empty string, setting one to `$null`
+or an empty string removes it. For example:
```powershell
-Set-Item -Path Env:Path -Value ($Env:Path + ";C:\Temp")
+$Env:Foo = ''
+$Env:Foo | Get-Member -MemberType Properties
```
-In this command, the value is enclosed in parentheses so that it is
-interpreted as a unit.
+```Output
+Get-Member : You must specify an object for the Get-Member cmdlet.
+At line:1 char:12
++ $env:foo | Get-Member++ ~~~~~~~~~~
+ + CategoryInfo : CloseError: (:) [Get-Member], InvalidOperationException
+ + FullyQualifiedErrorId : NoObjectInGetMember,Microsoft.PowerShell.Commands.GetMemberCommand
+```
-## Managing environment variables
+`Get-Member` returned an error because the environment variable was removed. You
+can see that it does not return an error when you use it on an empty string:
-PowerShell provides several different methods for managing environment
-variables.
+```powershell
+'' | Get-Member -MemberType Properties
+```
-- The Environment provider drive-- The Item cmdlets-- The .NET **System.Environment** class-- On Windows, the System Control Panel
+```Output
+ TypeName: System.String
-### Using the Environment provider
+Name MemberType Definition
+---- ---------- ----------
+Length Property int Length {get;}
+```
-Each environment variable is represented by an instance of the
-**System.Collections.DictionaryEntry** class. In each **DictionaryEntry**
-object, the name of the environment variable is the dictionary key. The value
-of the variable is the dictionary value.
+For more information about variables in PowerShell, see
+[about_Variables](about_variables.md).
-To display the properties and methods of the object that represents an
-environment variable in PowerShell, use the `Get-Member` cmdlet. For example,
-to display the methods and properties of all the objects in the `Env:` drive,
-type:
+## Using the Environment provider and Item cmdlets
-```powershell
-Get-Item -Path Env:* | Get-Member
-```
+PowerShell's **Environment** provider gives you an interface for interacting
+with environment variables in a format that resembles a file system drive. It
+lets you get, add, change, clear, and delete environment variables and values in
+PowerShell.
-The PowerShell Environment provider lets you access environment variables in a
-PowerShell drive (the `Env:` drive). This drive looks much like a file system
-drive. To go to the `Env:` drive, type:
+For example, to create the `Foo` environment variable with a value of `Bar`:
```powershell
-Set-Location Env:
+New-Item -Path Env:\Foo -Value 'Bar'
```
-Use the Content cmdlets to get or set the values of an environment variable.
+```Output
+Name Value
+---- -----
+Foo Bar
+```
+
+You can also copy the environment variable with `Copy-Item`, set the value of an
+environment variable with `Set-Item`, list environment variables with
+`Get-Item`, and delete the environment variable with `Remove-Item`.
```powershell
-PS Env:\> Set-Content -Path Test -Value 'Test value'
-PS Env:\> Get-Content -Path Test
-Test value
+Copy-Item -Path Env:\Foo -Destination Env:\Foo2 -PassThru
+Set-Item -Path Env:\Foo2 -Value 'BAR'
+Get-Item -Path Env:\Foo*
+Remove-Item -Path Env:\Foo* -Verbose
```
-You can view the environment variables in the `Env:` drive from any other
-PowerShell drive, and you can go into the `Env:` drive to view and change the
-environment variables.
-
-### Using Item cmdlets
+```Output
+Name Value
+---- -----
+Foo2 Bar
-When you refer to an environment variable, type the `Env:` drive name followed
-by the name of the variable. For example, to display the value of the
-`COMPUTERNAME` environment variable, type:
+Name Value
+---- -----
+Foo2 BAR
+Foo Bar
-```powershell
-Get-ChildItem Env:Computername
+VERBOSE: Performing the operation "Remove Item" on target "Item: Foo2".
+VERBOSE: Performing the operation "Remove Item" on target "Item: Foo".
```
-To display the values of all the environment variables, type:
+For more information on using the **Environment** provider to manage environment
+variables, see [about_Environment_Provider](about_Environment_Provider.md).
-```powershell
-Get-ChildItem Env:
-```
+## Using the System.Environment methods
-Because environment variables do not have child items, the output of `Get-Item`
-and `Get-ChildItem` is the same.
+The **System.Environment** class provides the **GetEnvironmentVariable** and
+**SetEnvironmentVariable** methods to get and modify environment variables.
-By default, PowerShell displays the environment variables in the order in which
-it retrieves them. To sort the list of environment variables by variable name,
-pipe the output of a `Get-ChildItem` command to the `Sort-Object` cmdlet. For
-example, from any PowerShell drive, type:
+The following example creates a new environment variable, `Foo`, with a value of
+`Bar` and then returns its value.
```powershell
-Get-ChildItem Env: | Sort Name
+[Environment]::SetEnvironmentVariable('Foo','Bar')
+[Environment]::GetEnvironmentVariable('Foo')
+```
+
+```Output
+Bar
```
-You can also go into the `Env:` drive by using the `Set-Location` cmdlet:
+You can remove an environment variable with the **SetEnvironmentVariable**
+method by specifying an empty string for the variable's value. For example,
+to remove the `Foo` environment variable:
```powershell
-Set-Location Env:
+[Environment]::SetEnvironmentVariable('Foo','')
+[Environment]::GetEnvironmentVariable('Foo')
```
-When you are in the `Env:` drive, you can omit the `Env:` drive name from the
-path. For example, to display all the environment variables, type:
+```Output
-```powershell
-PS Env:\> Get-ChildItem
```
-To display the value of the `COMPUTERNAME` variable from within the `Env:`
-drive, type:
+For more information about the methods of the **System.Environment** class, see
+[Environment Methods](/dotnet/api/system.environment).
+
+## Saving changes to environment variables
+
+On Windows, there are three methods for making a persistent change to an
+environment variable: setting them in your profile, using the
+**SetEnvironmentVariable** method, and using the System Control Panel.
+
+### Saving environment variables in your profile
+
+Any environment variable you add or change in your PowerShell profile is
+available in any session that loads your profile. This method works for any
+version of PowerShell on any supported platform.
+
+For example, to create the `CompanyUri` environment variable and update the
+`Path` environment variable to include the `C:\Tools` folder, add the following
+lines to your PowerShell profile:
```powershell
-PS Env:\> Get-ChildItem ComputerName
+$Env:CompanyUri = 'https://internal.contoso.com'
+$Env:Path += ';C:\Tools'
```
-### Saving changes to environment variables
+> [!NOTE]
+> On Linux or macOS, the colon (`:`) is used instead of a semi-colon(`;`) to
+> separate a new path from the path that precedes it in the list.
+
+You can get the path to your PowerShell profile with the `$PROFILE` automatic
+variable. For more information on profiles, see
+[about_Profiles](about_profiles.md).
-To make a persistent change to an environment variable on Windows, use the
-System Control Panel. Select **Advanced System Settings**. On the **Advanced**
-tab, click **Environment Variable...**. You can add or edit existing
-environment variables in the **User** and **System** (Machine) scopes. Windows
-writes these values to the Registry so that they persist across sessions and
-system restarts.
+### Saving environment variables with SetEnvironmentVariable
-Alternately, you can add or change environment variables in your PowerShell
-profile. This method works for any version of PowerShell on any supported
-platform.
+On Windows, you can specify a scope for the **SetEnvironmentVariable** method as
+the third parameter to set the environment variable in that scope. The machine
+and user scopes both persist outside of the current process, allowing you to
+save a new or changed environment variable.
-### Using System.Environment methods
+For example, to save a new environment variable `Foo` with the value `Bar`to the
+machine scope:
-The **System.Environment** class provides **GetEnvironmentVariable** and
-**SetEnvironmentVariable** methods that allow you to specify the scope of the
-variable.
+```powershell
+[Environment]::SetEnvironmentVariable('Foo', 'Bar', 'Machine')
+```
-The following example uses the **GetEnvironmentVariable** method to get the
-machine setting of `PSModulePath` and the **SetEnvironmentVariable** method
-to add the `C:\Program Files\Fabrikam\Modules` path to the value.
+You can delete an environment variable from the user or machine scope by setting
+the variable's value to an empty string.
```powershell
-$path = [Environment]::GetEnvironmentVariable('PSModulePath', 'Machine')
-$newpath = $path + ';C:\Program Files\Fabrikam\Modules'
-[Environment]::SetEnvironmentVariable("PSModulePath", $newpath, 'Machine')
+[Environment]::SetEnvironmentVariable('Foo', '', 'Machine')
```
-For more information about the methods of the **System.Environment** class, see
-[Environment Methods](/dotnet/api/system.environment).
+### Saving environment variables with the System Control Panel
+
+In the System Control Panel, you can add or edit existing environment variables
+in the **User** and **System** (Machine) scopes. Windows writes these values to
+the Registry so that they persist across sessions and system restarts.
+
+To make a persistent change to an environment variable on Windows using the
+System Control Panel:
+
+1. Open the System Control Panel.
+1. Select **System**.
+1. Select **Advanced System Settings**.
+1. Go to the **Advanced** tab.
+1. Select **Environment Variables...**.
+1. Make your changes.
## PowerShell's environment variables
The environment variables that store preferences include:
command and is written on a background thread sometime after a module is imported.
- Default location of the cache is:
+ The default location of the cache is:
- Windows PowerShell 5.1: `$env:LOCALAPPDATA\Microsoft\Windows\PowerShell` - PowerShell 6.0 and higher: `$env:LOCALAPPDATA\Microsoft\PowerShell`
The environment variables that store preferences include:
To change the default location of the cache, set the environment variable before starting PowerShell. Changes to this environment variable only affect
- child processes. The value should name a full path (including filename)
- that PowerShell has permission to create and write files.
+ child processes. The value should name a full path (including filename) that
+ PowerShell has permission to create and write files.
- To disable the file cache, set this value to an invalid location, for
- example:
+ To disable the file cache, set this value to an invalid location, for example:
```powershell # `NUL` here is a special device on Windows that cannot be written to,
The environment variables that store preferences include:
- **XDG_DATA_HOME** - **XDG_CACHE_HOME**
-### Terminal features
-
-Beginning in PowerShell 7.2, the following environment variables can be used to
-control the Virtual Terminal features like ANSI escape sequences that colorize
-output. Support for ANSI escape sequences can be turned off using the **TERM**
-or **NO_COLOR** environment variables.
--- **TERM**-
- The following values of `$env:TERM` change the behavior as follows:
-
- - `dumb` - sets `$Host.UI.SupportsVirtualTerminal = $false`
- - `xterm-mono` - sets `$PSStyle.OutputRendering = PlainText`
- - `xtermm` - sets `$PSStyle.OutputRendering = PlainText`
--- **NO_COLOR**-
- If `$env:NO_COLOR` exists, then `$PSStyle.OutputRendering` is set to
- **PlainText**. For more information about the **NO_COLOR** environment
- variable, see [https://no-color.org/](https://no-color.org/).
- ## See also - [about_Environment_Provider](about_Environment_Provider.md)-- [about_Modules](about_Modules.md)
+- [about_Profiles](about_profiles.md)
+- [about_Variables](about_variables.md)
+- [Environment Methods](/dotnet/api/system.environment)
[xdg-bds]: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
Microsoft.PowerShell.Core About Environment Variables (7.2) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.2/Microsoft.PowerShell.Core/About/about_Environment_Variables.md
---
-description: Describes how to access Windows environment variables in PowerShell.
+description: Describes how to access and manage environment variables in PowerShell.
Locale: en-US Previously updated : 11/15/2021 Last updated : 03/31/2022 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-7.2&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about Environment Variables
Title: about Environment Variables
# about_Environment_Variables ## Short description
-Describes how to access Windows environment variables in PowerShell.
+Describes how to access and manage environment variables in PowerShell.
## Long description
-Environment variables store information about the operating system
-environment. This information includes details such as the operating system
-path, the number of processors used by the operating system, and the location
-of temporary folders.
-
-The environment variables store data that is used by the operating system and
+Environment variables store data that is used by the operating system and
other programs. For example, the `WINDIR` environment variable contains the location of the Windows installation directory. Programs can query the value of this variable to determine where Windows operating system files are located. PowerShell can access and manage environment variables in any of the supported
-operating system platforms. The PowerShell environment provider simplifies this
-process by making it easy to view and change environment variables.
+operating system platforms. The PowerShell environment provider lets you get,
+add, change, clear, and delete environment variables in the current console.
-Environment variables, unlike other types of variables in PowerShell, are
+Environment variables, unlike other types of variables in PowerShell, are always
+stored as a string and can't be empty. Also unlike other variables, they are
inherited by child processes, such as local background jobs and the sessions in which module members run. This makes environment variables well suited to storing values that are needed in both parent and child processes.
-## Using and changing environment variables
- On Windows, environment variables can be defined in three scopes: - Machine (or System) scope
On Windows, environment variables can be defined in three scopes:
The _Process_ scope contains the environment variables available in the current process, or PowerShell session. This list of variables is inherited from the parent process and is constructed from the variables in the _Machine_ and
-_User_ scopes. Unix-based platforms only have the _Process_ scope.
+_User_ scopes.
+
+When you change environment variables in PowerShell, the change affects only
+the current session. This behavior resembles the behavior of the `Set` command
+in the Windows Command Shell and the `Setenv` command in UNIX-based
+environments. To change values in the Machine or User scopes, you must use the
+methods of the **System.Environment** class.
+
+To make changes to Machine-scoped variables, you must also have permission. If
+you try to change a value without sufficient permission, the command fails and
+PowerShell displays an error.
+
+PowerShell provides several different methods for using and managing environment
+variables.
+
+- The variable syntax
+- The Environment provider and Item cmdlets
+- The .NET **System.Environment** class
-You can display and change the values of environment variables without using a
-cmdlet by using a variable syntax with the environment provider. To display the
-value of an environment variable, use the following syntax:
+## Using the variable syntax
+
+You can display and change the values of environment variables with the
+following syntax:
``` $Env:<variable-name> ```
-For example, to display the value of the `WINDIR` environment variable, type
-the following command at the PowerShell command prompt:
+For example, to display the value of the `WINDIR` environment variable:
```powershell $Env:windir ```
+```Output
+C:\Windows
+```
+ In this syntax, the dollar sign (`$`) indicates a variable, and the drive name (`Env:`) indicates an environment variable followed by the variable name (`windir`).
-When you change environment variables in PowerShell, the change affects only
-the current session. This behavior resembles the behavior of the `Set` command
-in the Windows Command Shell and the `Setenv` command in UNIX-based
-environments. To change values in the Machine or User scopes, you must use the
-methods of the **System.Environment** class.
-
-To make changes to Machine-scoped variables, you must also have permission. If
-you try to change a value without sufficient permission, the command fails and
-PowerShell displays an error.
-
-You can change the values of variables without using a cmdlet using the
-following syntax:
+You can create and update the value of environment variables with the following
+syntax:
```powershell $Env:<variable-name> = "<new-value>" ```
-For example, to append `;c:\temp` to the value of the `Path` environment
-variable, use the following syntax:
+For example, to create the `Foo` environment variable:
```powershell
-$Env:Path += ";c:\temp"
+$Env:Foo = 'An example'
```
-On Linux or macOS, the colon (`:`) in the command separates the new path from
-the path that precedes it in the list.
+Because environment variables are always strings, you can use them like any
+other variable containing a string. For example:
```powershell
-$Env:PATH += ":/usr/local/temp"
+"The 'Foo' environment variable is set to: $Env:Foo"
+$Env:Foo += '!'
+$Env:Foo
```
-You can also use the Item cmdlets, such as `Set-Item`, `Remove-Item`, and
-`Copy-Item` to change the values of environment variables. For example, to use
-the `Set-Item` cmdlet to append `;c:\temp` to the value of the `Path`
-environment variable, use the following syntax:
+```Output
+The 'Foo' environment variable is set to: An example
-```powershell
-Remove-Item -Path Env:Path
+An example!
```
-In this command, the variable is cleared. Note that the environment
-variable is referenced as an Item path and `$` is not used.
+Because an environment variable can't be an empty string, setting one to `$null`
+or an empty string removes it. For example:
```powershell
-Set-Item -Path Env:Path -Value ($Env:Path + ";C:\Temp")
+$Env:Foo = ''
+$Env:Foo | Get-Member -MemberType Properties
```
-In this command, the value is enclosed in parentheses so that it is
-interpreted as a unit.
+```Output
+Get-Member : You must specify an object for the Get-Member cmdlet.
+At line:1 char:12
++ $env:foo | Get-Member++ ~~~~~~~~~~
+ + CategoryInfo : CloseError: (:) [Get-Member], InvalidOperationException
+ + FullyQualifiedErrorId : NoObjectInGetMember,Microsoft.PowerShell.Commands.GetMemberCommand
+```
-## Managing environment variables
+`Get-Member` returned an error because the environment variable was removed. You
+can see that it does not return an error when you use it on an empty string:
-PowerShell provides several different methods for managing environment
-variables.
+```powershell
+'' | Get-Member -MemberType Properties
+```
-- The Environment provider drive-- The Item cmdlets-- The .NET **System.Environment** class-- On Windows, the System Control Panel
+```Output
+ TypeName: System.String
-### Using the Environment provider
+Name MemberType Definition
+---- ---------- ----------
+Length Property int Length {get;}
+```
-Each environment variable is represented by an instance of the
-**System.Collections.DictionaryEntry** class. In each **DictionaryEntry**
-object, the name of the environment variable is the dictionary key. The value
-of the variable is the dictionary value.
+For more information about variables in PowerShell, see
+[about_Variables](about_variables.md).
-To display the properties and methods of the object that represents an
-environment variable in PowerShell, use the `Get-Member` cmdlet. For example,
-to display the methods and properties of all the objects in the `Env:` drive,
-type:
+## Using the Environment provider and Item cmdlets
-```powershell
-Get-Item -Path Env:* | Get-Member
-```
+PowerShell's **Environment** provider gives you an interface for interacting
+with environment variables in a format that resembles a file system drive. It
+lets you get, add, change, clear, and delete environment variables and values in
+PowerShell.
-The PowerShell Environment provider lets you access environment variables in a
-PowerShell drive (the `Env:` drive). This drive looks much like a file system
-drive. To go to the `Env:` drive, type:
+For example, to create the `Foo` environment variable with a value of `Bar`:
```powershell
-Set-Location Env:
+New-Item -Path Env:\Foo -Value 'Bar'
```
-Use the Content cmdlets to get or set the values of an environment variable.
+```Output
+Name Value
+---- -----
+Foo Bar
+```
+
+You can also copy the environment variable with `Copy-Item`, set the value of an
+environment variable with `Set-Item`, list environment variables with
+`Get-Item`, and delete the environment variable with `Remove-Item`.
```powershell
-PS Env:\> Set-Content -Path Test -Value 'Test value'
-PS Env:\> Get-Content -Path Test
-Test value
+Copy-Item -Path Env:\Foo -Destination Env:\Foo2 -PassThru
+Set-Item -Path Env:\Foo2 -Value 'BAR'
+Get-Item -Path Env:\Foo*
+Remove-Item -Path Env:\Foo* -Verbose
```
-You can view the environment variables in the `Env:` drive from any other
-PowerShell drive, and you can go into the `Env:` drive to view and change the
-environment variables.
+```Output
+Name Value
+---- -----
+Foo2 Bar
-### Using Item cmdlets
+Name Value
+---- -----
+Foo2 BAR
+Foo Bar
-When you refer to an environment variable, type the `Env:` drive name followed
-by the name of the variable. For example, to display the value of the
-`COMPUTERNAME` environment variable, type:
-
-```powershell
-Get-ChildItem Env:Computername
+VERBOSE: Performing the operation "Remove Item" on target "Item: Foo2".
+VERBOSE: Performing the operation "Remove Item" on target "Item: Foo".
```
-To display the values of all the environment variables, type:
+For more information on using the **Environment** provider to manage environment
+variables, see [about_Environment_Provider](about_Environment_Provider.md).
-```powershell
-Get-ChildItem Env:
-```
+## Using the System.Environment methods
-Because environment variables do not have child items, the output of `Get-Item`
-and `Get-ChildItem` is the same.
+The **System.Environment** class provides the **GetEnvironmentVariable** and
+**SetEnvironmentVariable** methods to get and modify environment variables.
-By default, PowerShell displays the environment variables in the order in which
-it retrieves them. To sort the list of environment variables by variable name,
-pipe the output of a `Get-ChildItem` command to the `Sort-Object` cmdlet. For
-example, from any PowerShell drive, type:
+The following example creates a new environment variable, `Foo`, with a value of
+`Bar` and then returns its value.
```powershell
-Get-ChildItem Env: | Sort Name
+[Environment]::SetEnvironmentVariable('Foo','Bar')
+[Environment]::GetEnvironmentVariable('Foo')
+```
+
+```Output
+Bar
```
-You can also go into the `Env:` drive by using the `Set-Location` cmdlet:
+You can remove an environment variable with the **SetEnvironmentVariable**
+method by specifying an empty string for the variable's value. For example,
+to remove the `Foo` environment variable:
```powershell
-Set-Location Env:
+[Environment]::SetEnvironmentVariable('Foo','')
+[Environment]::GetEnvironmentVariable('Foo')
```
-When you are in the `Env:` drive, you can omit the `Env:` drive name from the
-path. For example, to display all the environment variables, type:
+```Output
-```powershell
-PS Env:\> Get-ChildItem
```
-To display the value of the `COMPUTERNAME` variable from within the `Env:`
-drive, type:
+For more information about the methods of the **System.Environment** class, see
+[Environment Methods](/dotnet/api/system.environment).
+
+## Saving changes to environment variables
+
+On Windows, there are three methods for making a persistent change to an
+environment variable: setting them in your profile, using the
+**SetEnvironmentVariable** method, and using the System Control Panel.
+
+### Saving environment variables in your profile
+
+Any environment variable you add or change in your PowerShell profile is
+available in any session that loads your profile. This method works for any
+version of PowerShell on any supported platform.
+
+For example, to create the `CompanyUri` environment variable and update the
+`Path` environment variable to include the `C:\Tools` folder, add the following
+lines to your PowerShell profile:
```powershell
-PS Env:\> Get-ChildItem ComputerName
+$Env:CompanyUri = 'https://internal.contoso.com'
+$Env:Path += ';C:\Tools'
```
-### Saving changes to environment variables
+> [!NOTE]
+> On Linux or macOS, the colon (`:`) is used instead of a semi-colon(`;`) to
+> separate a new path from the path that precedes it in the list.
-To make a persistent change to an environment variable on Windows, use the
-System Control Panel. Select **Advanced System Settings**. On the **Advanced**
-tab, click **Environment Variable...**. You can add or edit existing
-environment variables in the **User** and **System** (Machine) scopes. Windows
-writes these values to the Registry so that they persist across sessions and
-system restarts.
+You can get the path to your PowerShell profile with the `$PROFILE` automatic
+variable. For more information on profiles, see
+[about_Profiles](about_profiles.md).
-Alternately, you can add or change environment variables in your PowerShell
-profile. This method works for any version of PowerShell on any supported
-platform.
+### Saving environment variables with SetEnvironmentVariable
-### Using System.Environment methods
+On Windows, you can specify a scope for the **SetEnvironmentVariable** method as
+the third parameter to set the environment variable in that scope. The machine
+and user scopes both persist outside of the current process, allowing you to
+save a new or changed environment variable.
-The **System.Environment** class provides **GetEnvironmentVariable** and
-**SetEnvironmentVariable** methods that allow you to specify the scope of the
-variable.
+For example, to save a new environment variable `Foo` with the value `Bar`to the
+machine scope:
-The following example uses the **GetEnvironmentVariable** method to get the
-machine setting of `PSModulePath` and the **SetEnvironmentVariable** method
-to add the `C:\Program Files\Fabrikam\Modules` path to the value.
+```powershell
+[Environment]::SetEnvironmentVariable('Foo', 'Bar', 'Machine')
+```
+
+You can delete an environment variable from the user or machine scope by setting
+the variable's value to an empty string.
```powershell
-$path = [Environment]::GetEnvironmentVariable('PSModulePath', 'Machine')
-$newpath = $path + ';C:\Program Files\Fabrikam\Modules'
-[Environment]::SetEnvironmentVariable("PSModulePath", $newpath, 'Machine')
+[Environment]::SetEnvironmentVariable('Foo', '', 'Machine')
```
-For more information about the methods of the **System.Environment** class, see
-[Environment Methods](/dotnet/api/system.environment).
+### Saving environment variables with the System Control Panel
+
+In the System Control Panel, you can add or edit existing environment variables
+in the **User** and **System** (Machine) scopes. Windows writes these values to
+the Registry so that they persist across sessions and system restarts.
+
+To make a persistent change to an environment variable on Windows using the
+System Control Panel:
+
+1. Open the System Control Panel.
+1. Select **System**.
+1. Select **Advanced System Settings**.
+1. Go to the **Advanced** tab.
+1. Select **Environment Variables...**.
+1. Make your changes.
## PowerShell's environment variables
The environment variables that store preferences include:
command and is written on a background thread sometime after a module is imported.
- Default location of the cache is:
+ The default location of the cache is:
- Windows PowerShell 5.1: `$env:LOCALAPPDATA\Microsoft\Windows\PowerShell` - PowerShell 6.0 and higher: `$env:LOCALAPPDATA\Microsoft\PowerShell`
The environment variables that store preferences include:
To change the default location of the cache, set the environment variable before starting PowerShell. Changes to this environment variable only affect
- child processes. The value should name a full path (including filename)
- that PowerShell has permission to create and write files.
+ child processes. The value should name a full path (including filename) that
+ PowerShell has permission to create and write files.
- To disable the file cache, set this value to an invalid location, for
- example:
+ To disable the file cache, set this value to an invalid location, for example:
```powershell # `NUL` here is a special device on Windows that cannot be written to,
or **NO_COLOR** environment variables.
## See also - [about_Environment_Provider](about_Environment_Provider.md)-- [about_Modules](about_Modules.md)
+- [about_Profiles](about_profiles.md)
+- [about_Variables](about_variables.md)
+- [Environment Methods](/dotnet/api/system.environment)
[xdg-bds]: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
Microsoft.PowerShell.Core About Environment Variables (7.3) https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/7.3/Microsoft.PowerShell.Core/About/about_Environment_Variables.md
---
-description: Describes how to access Windows environment variables in PowerShell.
+description: Describes how to access and manage environment variables in PowerShell.
Locale: en-US Previously updated : 11/15/2021 Last updated : 03/31/2022 online version: https://docs.microsoft.com/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-7.3&WT.mc_id=ps-gethelp schema: 2.0.0 Title: about Environment Variables
Title: about Environment Variables
# about_Environment_Variables ## Short description
-Describes how to access Windows environment variables in PowerShell.
+Describes how to access and manage environment variables in PowerShell.
## Long description
-Environment variables store information about the operating system
-environment. This information includes details such as the operating system
-path, the number of processors used by the operating system, and the location
-of temporary folders.
-
-The environment variables store data that is used by the operating system and
+Environment variables store data that is used by the operating system and
other programs. For example, the `WINDIR` environment variable contains the location of the Windows installation directory. Programs can query the value of this variable to determine where Windows operating system files are located. PowerShell can access and manage environment variables in any of the supported
-operating system platforms. The PowerShell environment provider simplifies this
-process by making it easy to view and change environment variables.
+operating system platforms. The PowerShell environment provider lets you get,
+add, change, clear, and delete environment variables in the current console.
-Environment variables, unlike other types of variables in PowerShell, are
+Environment variables, unlike other types of variables in PowerShell, are always
+stored as a string and can't be empty. Also unlike other variables, they are
inherited by child processes, such as local background jobs and the sessions in which module members run. This makes environment variables well suited to storing values that are needed in both parent and child processes.
-## Using and changing environment variables
- On Windows, environment variables can be defined in three scopes: - Machine (or System) scope
On Windows, environment variables can be defined in three scopes:
The _Process_ scope contains the environment variables available in the current process, or PowerShell session. This list of variables is inherited from the parent process and is constructed from the variables in the _Machine_ and
-_User_ scopes. Unix-based platforms only have the _Process_ scope.
+_User_ scopes.
+
+When you change environment variables in PowerShell, the change affects only
+the current session. This behavior resembles the behavior of the `Set` command
+in the Windows Command Shell and the `Setenv` command in UNIX-based
+environments. To change values in the Machine or User scopes, you must use the
+methods of the **System.Environment** class.
+
+To make changes to Machine-scoped variables, you must also have permission. If
+you try to change a value without sufficient permission, the command fails and
+PowerShell displays an error.
+
+PowerShell provides several different methods for using and managing environment
+variables.
+
+- The variable syntax
+- The Environment provider and Item cmdlets
+- The .NET **System.Environment** class
-You can display and change the values of environment variables without using a
-cmdlet by using a variable syntax with the environment provider. To display the
-value of an environment variable, use the following syntax:
+## Using the variable syntax
+
+You can display and change the values of environment variables with the
+following syntax:
``` $Env:<variable-name> ```
-For example, to display the value of the `WINDIR` environment variable, type
-the following command at the PowerShell command prompt:
+For example, to display the value of the `WINDIR` environment variable:
```powershell $Env:windir ```
+```Output
+C:\Windows
+```
+ In this syntax, the dollar sign (`$`) indicates a variable, and the drive name (`Env:`) indicates an environment variable followed by the variable name (`windir`).
-When you change environment variables in PowerShell, the change affects only
-the current session. This behavior resembles the behavior of the `Set` command
-in the Windows Command Shell and the `Setenv` command in UNIX-based
-environments. To change values in the Machine or User scopes, you must use the
-methods of the **System.Environment** class.
-
-To make changes to Machine-scoped variables, you must also have permission. If
-you try to change a value without sufficient permission, the command fails and
-PowerShell displays an error.
-
-You can change the values of variables without using a cmdlet using the
-following syntax:
+You can create and update the value of environment variables with the following
+syntax:
```powershell $Env:<variable-name> = "<new-value>" ```
-For example, to append `;c:\temp` to the value of the `Path` environment
-variable, use the following syntax:
+For example, to create the `Foo` environment variable:
```powershell
-$Env:Path += ";c:\temp"
+$Env:Foo = 'An example'
```
-On Linux or macOS, the colon (`:`) in the command separates the new path from
-the path that precedes it in the list.
+Because environment variables are always strings, you can use them like any
+other variable containing a string. For example:
```powershell
-$Env:PATH += ":/usr/local/temp"
+"The 'Foo' environment variable is set to: $Env:Foo"
+$Env:Foo += '!'
+$Env:Foo
```
-You can also use the Item cmdlets, such as `Set-Item`, `Remove-Item`, and
-`Copy-Item` to change the values of environment variables. For example, to use
-the `Set-Item` cmdlet to append `;c:\temp` to the value of the `Path`
-environment variable, use the following syntax:
+```Output
+The 'Foo' environment variable is set to: An example
-```powershell
-Remove-Item -Path Env:Path
+An example!
```
-In this command, the variable is cleared. Note that the environment
-variable is referenced as an Item path and `$` is not used.
+Because an environment variable can't be an empty string, setting one to `$null`
+or an empty string removes it. For example:
```powershell
-Set-Item -Path Env:Path -Value ($Env:Path + ";C:\Temp")
+$Env:Foo = ''
+$Env:Foo | Get-Member -MemberType Properties
```
-In this command, the value is enclosed in parentheses so that it is
-interpreted as a unit.
+```Output
+Get-Member : You must specify an object for the Get-Member cmdlet.
+At line:1 char:12
++ $env:foo | Get-Member++ ~~~~~~~~~~
+ + CategoryInfo : CloseError: (:) [Get-Member], InvalidOperationException
+ + FullyQualifiedErrorId : NoObjectInGetMember,Microsoft.PowerShell.Commands.GetMemberCommand
+```
-## Managing environment variables
+`Get-Member` returned an error because the environment variable was removed. You
+can see that it does not return an error when you use it on an empty string:
-PowerShell provides several different methods for managing environment
-variables.
+```powershell
+'' | Get-Member -MemberType Properties
+```
-- The Environment provider drive-- The Item cmdlets-- The .NET **System.Environment** class-- On Windows, the System Control Panel
+```Output
+ TypeName: System.String
-### Using the Environment provider
+Name MemberType Definition
+---- ---------- ----------
+Length Property int Length {get;}
+```
-Each environment variable is represented by an instance of the
-**System.Collections.DictionaryEntry** class. In each **DictionaryEntry**
-object, the name of the environment variable is the dictionary key. The value
-of the variable is the dictionary value.
+For more information about variables in PowerShell, see
+[about_Variables](about_variables.md).
-To display the properties and methods of the object that represents an
-environment variable in PowerShell, use the `Get-Member` cmdlet. For example,
-to display the methods and properties of all the objects in the `Env:` drive,
-type:
+## Using the Environment provider and Item cmdlets
-```powershell
-Get-Item -Path Env:* | Get-Member
-```
+PowerShell's **Environment** provider gives you an interface for interacting
+with environment variables in a format that resembles a file system drive. It
+lets you get, add, change, clear, and delete environment variables and values in
+PowerShell.
-The PowerShell Environment provider lets you access environment variables in a
-PowerShell drive (the `Env:` drive). This drive looks much like a file system
-drive. To go to the `Env:` drive, type:
+For example, to create the `Foo` environment variable with a value of `Bar`:
```powershell
-Set-Location Env:
+New-Item -Path Env:\Foo -Value 'Bar'
```
-Use the Content cmdlets to get or set the values of an environment variable.
+```Output
+Name Value
+---- -----
+Foo Bar
+```
+
+You can also copy the environment variable with `Copy-Item`, set the value of an
+environment variable with `Set-Item`, list environment variables with
+`Get-Item`, and delete the environment variable with `Remove-Item`.
```powershell
-PS Env:\> Set-Content -Path Test -Value 'Test value'
-PS Env:\> Get-Content -Path Test
-Test value
+Copy-Item -Path Env:\Foo -Destination Env:\Foo2 -PassThru
+Set-Item -Path Env:\Foo2 -Value 'BAR'
+Get-Item -Path Env:\Foo*
+Remove-Item -Path Env:\Foo* -Verbose
```
-You can view the environment variables in the `Env:` drive from any other
-PowerShell drive, and you can go into the `Env:` drive to view and change the
-environment variables.
+```Output
+Name Value
+---- -----
+Foo2 Bar
-### Using Item cmdlets
+Name Value
+---- -----
+Foo2 BAR
+Foo Bar
-When you refer to an environment variable, type the `Env:` drive name followed
-by the name of the variable. For example, to display the value of the
-`COMPUTERNAME` environment variable, type:
-
-```powershell
-Get-ChildItem Env:Computername
+VERBOSE: Performing the operation "Remove Item" on target "Item: Foo2".
+VERBOSE: Performing the operation "Remove Item" on target "Item: Foo".
```
-To display the values of all the environment variables, type:
+For more information on using the **Environment** provider to manage environment
+variables, see [about_Environment_Provider](about_Environment_Provider.md).
-```powershell
-Get-ChildItem Env:
-```
+## Using the System.Environment methods
-Because environment variables do not have child items, the output of `Get-Item`
-and `Get-ChildItem` is the same.
+The **System.Environment** class provides the **GetEnvironmentVariable** and
+**SetEnvironmentVariable** methods to get and modify environment variables.
-By default, PowerShell displays the environment variables in the order in which
-it retrieves them. To sort the list of environment variables by variable name,
-pipe the output of a `Get-ChildItem` command to the `Sort-Object` cmdlet. For
-example, from any PowerShell drive, type:
+The following example creates a new environment variable, `Foo`, with a value of
+`Bar` and then returns its value.
```powershell
-Get-ChildItem Env: | Sort Name
+[Environment]::SetEnvironmentVariable('Foo','Bar')
+[Environment]::GetEnvironmentVariable('Foo')
+```
+
+```Output
+Bar
```
-You can also go into the `Env:` drive by using the `Set-Location` cmdlet:
+You can remove an environment variable with the **SetEnvironmentVariable**
+method by specifying an empty string for the variable's value. For example,
+to remove the `Foo` environment variable:
```powershell
-Set-Location Env:
+[Environment]::SetEnvironmentVariable('Foo','')
+[Environment]::GetEnvironmentVariable('Foo')
```
-When you are in the `Env:` drive, you can omit the `Env:` drive name from the
-path. For example, to display all the environment variables, type:
+```Output
-```powershell
-PS Env:\> Get-ChildItem
```
-To display the value of the `COMPUTERNAME` variable from within the `Env:`
-drive, type:
+For more information about the methods of the **System.Environment** class, see
+[Environment Methods](/dotnet/api/system.environment).
+
+## Saving changes to environment variables
+
+On Windows, there are three methods for making a persistent change to an
+environment variable: setting them in your profile, using the
+**SetEnvironmentVariable** method, and using the System Control Panel.
+
+### Saving environment variables in your profile
+
+Any environment variable you add or change in your PowerShell profile is
+available in any session that loads your profile. This method works for any
+version of PowerShell on any supported platform.
+
+For example, to create the `CompanyUri` environment variable and update the
+`Path` environment variable to include the `C:\Tools` folder, add the following
+lines to your PowerShell profile:
```powershell
-PS Env:\> Get-ChildItem ComputerName
+$Env:CompanyUri = 'https://internal.contoso.com'
+$Env:Path += ';C:\Tools'
```
-### Saving changes to environment variables
+> [!NOTE]
+> On Linux or macOS, the colon (`:`) is used instead of a semi-colon(`;`) to
+> separate a new path from the path that precedes it in the list.
-To make a persistent change to an environment variable on Windows, use the
-System Control Panel. Select **Advanced System Settings**. On the **Advanced**
-tab, click **Environment Variable...**. You can add or edit existing
-environment variables in the **User** and **System** (Machine) scopes. Windows
-writes these values to the Registry so that they persist across sessions and
-system restarts.
+You can get the path to your PowerShell profile with the `$PROFILE` automatic
+variable. For more information on profiles, see
+[about_Profiles](about_profiles.md).
-Alternately, you can add or change environment variables in your PowerShell
-profile. This method works for any version of PowerShell on any supported
-platform.
+### Saving environment variables with SetEnvironmentVariable
-### Using System.Environment methods
+On Windows, you can specify a scope for the **SetEnvironmentVariable** method as
+the third parameter to set the environment variable in that scope. The machine
+and user scopes both persist outside of the current process, allowing you to
+save a new or changed environment variable.
-The **System.Environment** class provides **GetEnvironmentVariable** and
-**SetEnvironmentVariable** methods that allow you to specify the scope of the
-variable.
+For example, to save a new environment variable `Foo` with the value `Bar`to the
+machine scope:
-The following example uses the **GetEnvironmentVariable** method to get the
-machine setting of `PSModulePath` and the **SetEnvironmentVariable** method
-to add the `C:\Program Files\Fabrikam\Modules` path to the value.
+```powershell
+[Environment]::SetEnvironmentVariable('Foo', 'Bar', 'Machine')
+```
+
+You can delete an environment variable from the user or machine scope by setting
+the variable's value to an empty string.
```powershell
-$path = [Environment]::GetEnvironmentVariable('PSModulePath', 'Machine')
-$newpath = $path + ';C:\Program Files\Fabrikam\Modules'
-[Environment]::SetEnvironmentVariable("PSModulePath", $newpath, 'Machine')
+[Environment]::SetEnvironmentVariable('Foo', '', 'Machine')
```
-For more information about the methods of the **System.Environment** class, see
-[Environment Methods](/dotnet/api/system.environment).
+### Saving environment variables with the System Control Panel
+
+In the System Control Panel, you can add or edit existing environment variables
+in the **User** and **System** (Machine) scopes. Windows writes these values to
+the Registry so that they persist across sessions and system restarts.
+
+To make a persistent change to an environment variable on Windows using the
+System Control Panel:
+
+1. Open the System Control Panel.
+1. Select **System**.
+1. Select **Advanced System Settings**.
+1. Go to the **Advanced** tab.
+1. Select **Environment Variables...**.
+1. Make your changes.
## PowerShell's environment variables
The environment variables that store preferences include:
command and is written on a background thread sometime after a module is imported.
- Default location of the cache is:
+ The default location of the cache is:
- Windows PowerShell 5.1: `$env:LOCALAPPDATA\Microsoft\Windows\PowerShell` - PowerShell 6.0 and higher: `$env:LOCALAPPDATA\Microsoft\PowerShell`
The environment variables that store preferences include:
To change the default location of the cache, set the environment variable before starting PowerShell. Changes to this environment variable only affect
- child processes. The value should name a full path (including filename)
- that PowerShell has permission to create and write files.
+ child processes. The value should name a full path (including filename) that
+ PowerShell has permission to create and write files.
- To disable the file cache, set this value to an invalid location, for
- example:
+ To disable the file cache, set this value to an invalid location, for example:
```powershell # `NUL` here is a special device on Windows that cannot be written to,
or **NO_COLOR** environment variables.
## See also - [about_Environment_Provider](about_Environment_Provider.md)-- [about_Modules](about_Modules.md)
+- [about_Profiles](about_profiles.md)
+- [about_Variables](about_variables.md)
+- [Environment Methods](/dotnet/api/system.environment)
[xdg-bds]: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
community 2022 Updates https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/community/2022-updates.md
--- description: List of changes to the PowerShell documentation for 2022 Previously updated : 03/02/2022 Last updated : 04/01/2022 Title: What's New in PowerShell-Docs for 2022 --- # What's new in PowerShell Docs for 2022
contributions from the community.
Help us make the documentation better for you. Read the [Contributor's Guide][contrib] to learn how to get started.
+## 2022-March
+
+New Content
+
+- New PowerShell docs
+ - [about_Member-Access_Enumeration](/powershell/module/microsoft.powershell.core/about/about_member-access_enumeration)
+ - [about_Module_Manifests](/powershell/module/microsoft.powershell.core/about/about_module_manifests)
+ - [How to create a command-line predictor](/powershell/scripting/dev-cross-plat/create-cmdline-predictor)
+- Utility modules updates
+ - New docs for Crescendo release
+ - [Install Crescendo](/powershell/utility-modules/crescendo/get-started/install-crescendo)
+ - [Choose a command-line tool](/powershell/utility-modules/crescendo/get-started/choose-command-line-tool)
+ - [Decide which features to amplify](/powershell/utility-modules/crescendo/get-started/research-tool)
+ - [Create a Crescendo cmdlet](/powershell/utility-modules/crescendo/get-started/create-new-cmdlet)
+ - [Generate and test a Crescendo module](/powershell/utility-modules/crescendo/get-started/generate-module)
+ - We have plans for at least two more documents
+ - Moved PlatyPS article from PowerShell docs to the PlatyPS documentation
+ - [Moved PlatyPS article](/powershell/utility-modules/platyps/create-help-using-platyps)
+ - Migrated more PSScriptAnalyzer documentation from the source code repository
+ - [Using PSScriptAnalyzer](/powershell/utility-modules/psscriptanalyzer/using-scriptanalyzer)
+ - [Rules and recommendations](/powershell/utility-modules/psscriptanalyzer/rules-recommendations)
+ - [Creating custom rules](/powershell/utility-modules/psscriptanalyzer/create-custom-rule)
+
+Content updates
+
+- Bulk cleanup of related links in About_ topics
+- Added issue and PR templates to all docs repos
+- Updates for 7.3 preview content
+ - New tab completions
+ - Support for SSH options on remoting cmdlets
+ - New experimental feature `PSAMSIMethodInvocationLogging`
+
+Other projects
+
+- Created a prototype cmdlet `Get-WhatsNew` based on the
+ [draft RFC](https://github.com/PowerShell/PowerShell-RFC/pull/317)
+ - Check out the RFC and provide feedback
+
+New team member
+
+- Welcome [Mikey Lombardi](https://github.com/michaeltlombardi) to the docs team
+
+### Top Community Contributors
+
+GitHub stats
+
+- 49 PRs merged (8 from Community)
+- 26 issues opened (14 from Community)
+- 33 issues closed (18 Community issues closed)
+
+The following people have contributed to PowerShell docs by submitting pull requests or filing
+issues. Thank you!
+
+| GitHub Id | PRs merged | Issues opened |
+| -------------- | :--------: | :-----------: |
+| AspenForester | 1 | |
+| codaamok | 1 | |
+| DianaKuzmenko | 1 | |
+| MikeyBronowski | 1 | |
+| poshdude | 1 | |
+| robcmo | 1 | |
+| sertdfyguhi | 1 | |
+| stampycode | 1 | |
+ ## 2022-February New Content -- [about_Calling_Generic_Methods](/powershell/module/microsoft.powershell.core/about/about_calling_generic_methods?view=powershell-7.3&preserve-view=true)
+- [about_Calling_Generic_Methods](/powershell/module/microsoft.powershell.core/about/about_calling_generic_methods&preserve-view=true)
Content updates
community Hall Of Fame https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/community/hall-of-fame.md
--- description: List of the GitHub users that have the most contributions to the PowerShell-Doc project. Previously updated : 03/02/2022 Last updated : 04/01/2022 Title: Community contributor Hall of Fame --- # Community Contributor Hall of Fame
The PowerShell Community is a vibrant and collaborative group. We greatly apprec
and support we get from the community. Learn how you can contribute by reading the [Contributor's Guide][contrib].
-As of the end of February 2022, these GitHub users are the All-Time Top Community Contributors.
+As of the end of March 2022, these GitHub users are the All-Time Top Community Contributors.
-## Pull Requests opened
+## Pull Requests merged
Pull Requests help us fix those issues and make the documentation better for everyone.
-| Docs PRs Merged | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | Grand Total |
+| PRs Merged | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | Grand Total |
| --------------- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ----------: |
-| Community | 3 | 194 | 446 | 464 | 318 | 161 | 100 | 13 | 1699 |
+| Community | 3 | 194 | 446 | 464 | 318 | 161 | 100 | 21 | 1707 |
| matt9ucci | | | 157 | 80 | 30 | 1 | 6 | | 274 | | nschonni | | | | 14 | 138 | 10 | | | 162 | | kiazhi | | 25 | 79 | 12 | | | | | 116 |
Pull Requests help us fix those issues and make the documentation better for eve
| skycommand | | | 1 | 3 | 3 | 6 | | | 13 | | purdo17 | | | | 13 | | | | | 13 | | k-takai | | | | 5 | 1 | 7 | | | 13 |
-| PlagueHO | | 10 | | | 1 | | | | 11 |
| exchange12rocks | | | 7 | 3 | | | 1 | | 11 |
+| PlagueHO | | 10 | | | 1 | | | | 11 |
+ ## GitHub issues opened GitHub issues help us identify errors and gaps in our documentation.
-| Docs Issues Opened | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | Grand Total |
-| ------------------ | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ----------: |
-| Community | 3 | 54 | 95 | 212 | 559 | 561 | 333 | 12 | 1829 |
-| mklement0 | | | 19 | 60 | 56 | 61 | 27 | | 223 |
-| iSazonov | | | 1 | 4 | 10 | 8 | 3 | | 26 |
-| jszabo98 | | | | 2 | 15 | 6 | 1 | | 24 |
-| juvtib | | | | | | 15 | 7 | | 22 |
-| doctordns | | | 5 | 3 | 5 | 6 | 1 | | 20 |
-| vexx32 | | | | 3 | 11 | | | 1 | 15 |
-| alexandair | | 9 | 4 | 2 | | | | | 15 |
-| clamb123 | | | | | | | 14 | | 14 |
-| KirkMunro | | | | 7 | 5 | 1 | | | 13 |
-| trollyanov | | | | | | | 11 | | 11 |
-| JustinGrote | | | | 1 | 3 | 6 | 1 | | 11 |
-| vors | 1 | 6 | 2 | 1 | | | | | 10 |
-| rkeithhill | | | 1 | 2 | 2 | 2 | 3 | | 10 |
+| Issues Opened | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | Grand Total |
+| ------------- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ----------: |
+| Community | 3 | 54 | 95 | 212 | 566 | 563 | 368 | 59 | 1920 |
+| mklement0 | | | 19 | 60 | 56 | 61 | 28 | | 224 |
+| iSazonov | | | 1 | 4 | 10 | 8 | 4 | | 27 |
+| jszabo98 | | | | 2 | 15 | 6 | 1 | | 24 |
+| juvtib | | | | | | 15 | 7 | | 22 |
+| doctordns | | | 5 | 3 | 5 | 7 | 1 | | 21 |
+| vexx32 | | | | 3 | 11 | | | 1 | 15 |
+| KirkMunro | | | | 7 | 7 | 1 | | | 15 |
+| alexandair | | 9 | 4 | 2 | | | | | 15 |
+| clamb123 | | | | | | | 14 | | 14 |
+| trollyanov | | | | | | | 11 | | 11 |
+| rkeithhill | | | 1 | 2 | 2 | 2 | 3 | 1 | 11 |
+| JustinGrote | | | | 1 | 3 | 6 | 1 | | 11 |
+| vors | 1 | 6 | 2 | 1 | | | | | 10 |
+| UberKluger | | | | | | 1 | 7 | 2 | 10 |
<!-- Link references --> [contrib]: contributing/overview.md
whats-new What S New In Powershell 70 https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/whats-new/What-s-New-in-PowerShell-70.md
For more information about
- Fix a typo in README.md (#10465) (Thanks @vedhasp!) - Add a reference to PSKoans module to Learning Resources documentation (#10369) (Thanks @vexx32!) - Update README.md and metadata.json for 7.0.0-preview.3 (#10393)+
+<!-- end of content -->
whats-new What S New In Powershell 71 https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/whats-new/What-s-New-in-PowerShell-71.md
The following experimental features were added in this release:
work with in C# code. After this change, the returned object is the underlying object.+
+<!-- end of content -->
whats-new What S New In Powershell 72 https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/whats-new/What-s-New-in-PowerShell-72.md
Install-Module -Name PSDesiredStateConfiguration -Repository PSGallery -MaximumV
- Change `FileSystemInfo.Target` from a **CodeProperty** to an **AliasProperty** that points to `FileSystemInfo.LinkTarget` (#16165)
+<!-- end of content -->
<!-- reference links --> [announced]: https://devblogs.microsoft.com/powershell/announcing-powershell-7-2/
whats-new What S New In Powershell 73 https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/whats-new/What-s-New-in-PowerShell-73.md
For more information about the Experimental Features, see [Using Experimental Fe
resource cleanup (#15177) - Change default for `$PSStyle.OutputRendering` to **Ansi**
+<!-- end of content -->
<!-- reference links --> [CHANGELOG]: https://github.com/PowerShell/PowerShell/releases/tag/v7.3.0-preview.2
windows-powershell What S New In Windows Powershell 50 https://github.com/MicrosoftDocs/PowerShell-Docs/commits/staging/reference/docs-conceptual/windows-powershell/whats-new/What-s-New-in-Windows-PowerShell-50.md
cmdlets. The parser also includes special logic to improve handling of the backt
- [about_Windows_PowerShell_5.0](/previous-versions/powershell/module/microsoft.powershell.core/about/about_windows_powershell_5.0) - [Windows PowerShell](/powershell/)
+<!-- end of content -->
<!-- link refs --> [KB 3000850]: https://support.microsoft.com/topic/november-2014-update-rollup-for-windows-rt-8-1-windows-8-1-and-windows-server-2012-r2-7be5865b-adaa-dbbf-e2d4-1f819e7c9d87