Here we discuss some ways to set the PowerShell Path variable to meet our requirements.
We would look at the following scenarios.
Check the current PATH
Change the Current PATH
Append to the Current PATH
Make the PATH changes permanent.
Check the current PATH
To find out the current PowerShell Path, run the below cmd in PowerShell.
$env:PathChange the Current PATH
This would completely change the existing PATH to the new PATH defined by you.
$env:Path = "C:\newpath;c:\newpath64";
Append to the Current PATH
This could be the best way to consider if you would like to change the PATH, so that you may not end up breaking some dependencies that may be needed.
$env:Path += ";C:\Program Files\NewApp\bin;C:\Program Files\NewApp\Lib"Please pay attention to the semicolon ";" before the new PATH folders, if this is missed it could break the PATH variable syntax, the command may go through, but you may not get the desired output.
Make the PATH changes permanent.
And finally make the PATH changes permanent for your profile when ever you open PowerShell.
By default the user profile loads this PATH,
[Environment]::SetEnvironmentVariable("Path", "C:\Program Files\NewApp\bin;C:\Program Files\NewApp\Lib" , [EnvironmentVariableTarget]::User)
The path would not change immediately, we need to re-open the session for this to work!
This would actually create a key at HKEY_CURRENT_USER\Environment :: PATH with the Folders added. When the profile loads this would be appended to the existing PATH.
If you want to revert, delete the KEY PATH at HKEY_CURRENT_USER\Environment\
Happy Scripting!
No comments:
Post a Comment