A simple PowerShell module enabling loading of .env files into a PowerShell session. Takes inspiration from the node norm of env files. It simply picks up your key value pairs from .env, and loads them into transient environment variables. They can be optionally cleaned up at the end of the session, or the session can just be destroyed.
Install, call.
Find-Module dotenv
Install-Module dotenv
Import-Module dotenv
Set-DotEnv # loads from the local .env file
# code here
Remove-DotEnv # clears the variables that were loaded by set-dotenvIf you want to keep several .env files alongside your repo, you can use the path parameter to load a specific file.
Import-Module dotenv
Set-DotEnv -Path ./env.staging
# code here
Remove-DotEnvThis module can handle values with an extra '=' in them, and can handle quoted strings (single and double). For more complex scenarios, it may be advisable to base64 encode the values, and then decode as they're needed.
- Allow append and prepend with
:=/=:syntax - Extra testing, especially around injection of 'bad' vars, because we're dealing with possible third-party input here
Contribs welcome, please put in a PR and notify @cloudyopspoet on Twitter that you've done it, as notifications don't always make it through from github.