Created
December 22, 2021 20:09
-
-
Save colonelpopcorn/b8cab86798fa708d892d27c3e43cf36a to your computer and use it in GitHub Desktop.
Set Environment from powershell with .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
$content = Get-Content "./.env"; | |
$contentArr = $content.Trim().Split([Environment]::NewLine); | |
ForEach-Object -InputObject $contentArr { | |
$keyValPair = $_.Split("=", 2); | |
$key = $keyValPair[0].Trim(); | |
$val = $keyValPair[1].Trim(); | |
$envSign = '$env:' | |
$afterEnvSign = "$key=$val" | |
Invoke-Expression "$envSign$afterEnvSign"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment