powershellenvironment-variables

How do I read a .env file from a .ps1 script?


I have a .env file like this one:

TESTCASE_GROUP_SIZE=25
. . .

And I want to get its value (read it) into a .ps1 script. How can I do it?


Solution

  • get-content test.env | foreach {
        $name, $value = $_.split('=')
        set-content env:\$name $value
    }
    

    assuming you mean "set one environment variable per line in the file".