Skip to content

Instantly share code, notes, and snippets.

@jwatney
Last active June 5, 2019 23:34
Show Gist options
  • Save jwatney/c00ac732f2d3ebec58801e7ff17a8408 to your computer and use it in GitHub Desktop.
Save jwatney/c00ac732f2d3ebec58801e7ff17a8408 to your computer and use it in GitHub Desktop.
Writes env vars matching a prefix to a file. E.g. `write-env-vars.ps1 -Prefix MYAPP_ -Path Environment.config` Useful if you want env vars from your build system to be available to your deployed app.
param([String] $prefix, [String] $path)
# Write-Out environment variables to file.
Get-ChildItem env:* | Where-Object Name -Like "$($prefix)*" | ForEach-Object {
$name = $_.Name.Replace("_", ".")
$key = $name -Replace ":([\d]+):", "[`${1}]"
Write-Output "$key=$($_.Value)"
} | Out-File -FilePath $path
@jwatney
Copy link
Author

jwatney commented Jun 5, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment