Last active
March 21, 2023 12:51
-
-
Save bovrhovn/a7bca4432b0378834f35e5711eb095e2 to your computer and use it in GitHub Desktop.
PowerShell function for reading env file from
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
param( | |
[Parameter(HelpMessage = "File with env variables", Mandatory = $true)] | |
[string] | |
$EnvFile | |
) | |
if (!(Test-Path $EnvFile -PathType Leaf)) { | |
Write-Error "$EnvFile is not a file." | |
return; | |
} | |
Get-Content $EnvFile | ForEach-Object { | |
$name, $value = $_.split('=') | |
Write-Information "$name=$value" | |
Set-Content env:\$name $value | |
Write-Output "Writing $name to environment variable with $value." | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment