Skip to content

Instantly share code, notes, and snippets.

@bovrhovn
Last active March 21, 2023 12:51
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 bovrhovn/a7bca4432b0378834f35e5711eb095e2 to your computer and use it in GitHub Desktop.
Save bovrhovn/a7bca4432b0378834f35e5711eb095e2 to your computer and use it in GitHub Desktop.
PowerShell function for reading env file from
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