RIAS
asked on
Script to set env variables
How to write a script for env variables for system
ASKER
Spot on will try and brb
ASKER
Worked perfectly! Thanks
ASKER
How to do this in bulk. Example: I have 10 env variables to set.
Thanks
Thanks
Depends - if you have 10 different variables to set, they'll probably have 10 different values as well, so how/where is the information coming from?
ASKER
so what I did is that just repeated the lines one after the other. Example
[Environment]::SetEnvironm entVariabl e …
[Environment]::SetEnvironm entVariabl e…
And it worked.
Quick question, how can I change the variablename from uppercase to lowercase.
Example: Need to change ‘Path’ to ‘path’
Thanks
[Environment]::SetEnvironm
[Environment]::SetEnvironm
And it worked.
Quick question, how can I change the variablename from uppercase to lowercase.
Example: Need to change ‘Path’ to ‘path’
Thanks
ASKER
sorry edited the above comment as there was typo
The case of an environment variable name doesn't matter for Windows, so it will just change the value.
If you need to change the case of an existing variable, you need to delete the existing one first (by using $null as value).
If you need to change the case of an existing variable, you need to delete the existing one first (by using $null as value).
ASKER
sure, but, how can I can change the variablename from Path to path. It is a required step. Hope there is a way to do so in powershell?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect and amazing as always!!!
ASKER
Excellent solution provided!!!
ASKER
Thanks a ton
ASKER
Is ‘machine’ equivalent to ‘system’ Just confirming. Also how do I save this as a script?
ASKER
cannot see the file option when I open powershell as admin?
Yes, "Machine" in this context means "System" as used in the GUI.
You save it as Whatever.ps1 in the text editor of your choice.
You save it as Whatever.ps1 in the text editor of your choice.
ASKER
Thanks again. But notepad doesn’t save it as powershell script.
ASKER
it still opens in notepad and not in powershell admin prompt mode
Configure Explorer to show file extensions and save again, or enclose the name (including the .ps1 extension) into double quotes when saving in Notepad.
ASKER
Thanks again.
ASKER
The case change of Environmental name did not work.
I have an env name ‘Path’ with a variable value : C:/
need to change it to
env name ‘path’ with a variable value ‘C:/‘
I have an env name ‘Path’ with a variable value : C:/
need to change it to
env name ‘path’ with a variable value ‘C:/‘
ASKER
your earlier suggestion just changes the variable value and not the variable name
It might not work with Path that way, since this is a special environment variable; it can be defined both in User and Machine context and their values will be joined if it's found in both.
You can try to reset the the variable for both "Machine" and "User" (which will then obviously only work for the account you're running this under), but that might not work, or only until a reboot.
But then again: which kind of software insists, on an OS where environment variable names are case insensitive by default, on a lower case variable that is part of the OS and has been named "Path" with an uppercase P basically for forever and a day?
Not to mention that setting Path to C:\ will cause all kinds of problems, what with the Windows and System32 directories missing ...
You can try to reset the the variable for both "Machine" and "User" (which will then obviously only work for the account you're running this under), but that might not work, or only until a reboot.
But then again: which kind of software insists, on an OS where environment variable names are case insensitive by default, on a lower case variable that is part of the OS and has been named "Path" with an uppercase P basically for forever and a day?
Not to mention that setting Path to C:\ will cause all kinds of problems, what with the Windows and System32 directories missing ...
ASKER
Definitely I agree. But, looks like it a part of the process to change Path to path. But can be achieved manually.
Thanks
Thanks
Open in new window
Example:Open in new window
This will set a persistent variable, but only for new processes.If you want it in the current session as well, run the same command again, but with "Process" as target instead of System.
Open in new window
To remove the variable, use $null as value:Open in new window