-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Prerequisites
- Write a descriptive title.
- Search the existing issues.
- I am reporting the documentation problem for version of PowerShell I am using.
Version
5.1, 7.0, 7.1, 7.2, 7.3 (preview)
Link to affected document
Description of the documentation error
At the end of the "Using and changing environment variables" section, the documentation mentions the usage of Item cmdlets to manage environment variable values. I find the examples provided in this final paragraph confusing:
For example, to use the
Set-Itemcmdlet to append;c:\tempto the value of thePathenvironment variable, use the following syntax:Remove-Item -Path Env:PathIn this command, the variable is cleared. Note that the environment variable is referenced as an Item path and
$is not used.Set-Item -Path Env:Path -Value ($Env:Path + ";C:\Temp")In this command, the value is enclosed in parentheses so that it is interpreted as a unit.
It first mentions using Set-Item then proceeds to provide the syntax for Remove-Item.
Additionally, I find this example quite dangerous for a new user who doesn't know the potential consequences of executing this command.
Suggested fix
I'd replace the first example's path variable with a bogus one, such as Foo, then mention in the second example that we have appended ;c:\temp to the value of Path:
For example, to use the
Remove-Itemcmdlet to clear the value of theFooenvironment variable, use the following syntax:Remove-Item -Path Env:FooNote that the environment variable is referenced as an Item path and
$is not used.Set-Item -Path Env:Path -Value ($Env:Path + ";C:\Temp")In this command, we have appended
;C:\Tempto the value of thePathenvironment variable. Note that the value is enclosed in parentheses so that it is interpreted as a unit.