This topic contains 6 replies, has 2 voices, and was last updated by
July 10, 2015 at 5:07 am #27382
Hey folks. I am referencing this article https://technet.microsoft.com/en-us/library/ff730964.aspx
I want to create an environment variable for
What value / data-type must you specify for the “Test value.” parameter when using the
July 10, 2015 at 5:09 am #27383KeymasterPoints: 2Rank: Member
You're referring to:
[Environment]::SetEnvironmentVariable("TestVariable", "Test value.", "User")
They're all strings.
July 10, 2015 at 5:22 am #27385
Yes that method. Oh so it's just a simple string
July 10, 2015 at 6:28 am #27386
Don do you know if it is possible to delete files in an environment variable? by piping
July 10, 2015 at 6:52 am #27387KeymasterPoints: 2Rank: Member
Anything involving a PSDrive, including ENV:, will only affect the current process. But – and I'll explain my process here, in case that helps you – I Googled ".NET Environment Class." That got me to https://msdn.microsoft.com/en-us/library/system.environment(v=vs.110).aspx, which is the class you were using to set a variable.
I clicked on Methods, which got me to https://msdn.microsoft.com/en-us/library/system.environment_methods(v=vs.110).aspx.
I didn't see a "RemoveEnvironmentVariable" method, which made me sad. So I looked at the docs for SetEnvironmentVariable. Specifically, https://msdn.microsoft.com/en-us/library/96xafkes(v=vs.110).aspx.
That told me that the method could also DELETE a variable. Winner! You just pass $null as the value, and if the variable exists, it gets deleted.
Hope that helps.
July 10, 2015 at 3:45 pm #27396
Thanks! To verify it's deleted you can also use the method
July 14, 2015 at 6:55 am #27497
I ran into an 'issue' / limitation while using this method. I needed to create an environment variable for the local app-data directory
%USERPROFILE%\AppData\Local\Apps\2.0\. I tried creating a variable which used the
targetparameter, to access user profiles on remote machines. as a work around I used the following code to access the local app-data!
new-item -path $env:UserProfile\AppData\Local\Apps\2.0\ -itemtype directory -force
The topic ‘Creating and Modifying Environment Variables’ is closed to new replies.