I created a .env file to host some api authentication keys for my various python and powershell scripts. I'm trying to get my powershell script to read the file and set the variables, but it doesn't seem to work. This is the command I'm using to set the variables, adapted from this answer.
switch -File .\wkspaces\IT-Scripts\New-UserCredentials.env {
default {
$name, $value = $_.Trim() -split '=', 2
if ($name -and $name[0] -ne '#') { # ignore blank and comment lines.
Set-Item "Env:$name" $value
}
}
}
When I try to call the variable, it's just blank as if it doesn't exist. I am not using any spaces between the name and value in the .env file.