Created
June 19, 2018 14:28
-
-
Save JeremySkinner/d3a12fcb79ec834c25a32d9f22490781 to your computer and use it in GitHub Desktop.
Import env file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Import-EnvFile { | |
$files = Get-ChildItem *.env | |
foreach($file in $files) { | |
write-host $file | |
$lines = Get-Content $file | |
foreach($line in $lines) { | |
if ($line -and !$line.StartsWith("#")) { | |
# Split by equals | |
$parts = $line.Split("=") | |
if ($parts.Length -eq 2) { | |
$name = $parts[0].Trim() | |
$value = $parts[1].Trim() | |
[Environment]::SetEnvironmentVariable($name, $value) | |
# If you want, you can set it user-wide (rather than just current shell) | |
# But that's much slower | |
# [Environment]::SetEnvironmentVariable($name, $value, 'User) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment