Reputation: 17745
I want to set some environment variables that are specified in a file.
Using setx
works fine for one environment at a time, but how can I pipe a file with the below contents
FOO bar
BAR foo
I was thinking something like this
setx < cat envvars.txt
but of course it doesn't work.
Upvotes: 0
Views: 613
Reputation: 31
Slight modification to the accepted answer if you created file.txt using:
SET >> file.txt
Get-Content file.txt | Foreach-Object {SETX $_.split("=")}
Upvotes: 1
Reputation: 2448
You're looking for a Foreach-Object
loop to start SETX
along with the current item within the loop.
An example:
Get-Content c:\file.txt | Foreach-Object {SETX [Options] $_}
We get the contents of a file, c:\file.txt, and for every item use SETX
Upvotes: 1