Skip to content

Instantly share code, notes, and snippets.

@colonelpopcorn
Created December 22, 2021 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colonelpopcorn/b8cab86798fa708d892d27c3e43cf36a to your computer and use it in GitHub Desktop.
Save colonelpopcorn/b8cab86798fa708d892d27c3e43cf36a to your computer and use it in GitHub Desktop.
Set Environment from powershell with .env file
$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