PowerShell module offering utilities to read environment variables from dotenv
files, or hashmap
instances.
# Create an dotenv example file
'HELLO=WORLD' > .env
# Import it into the current session
New-Environment .env
# Check if current environment contains the var
$env:HELLO -eq 'WORLD'
# Remove previously created environment
Remove-Environment -Verbose
VERBOSE: Removing environment variable "HELLO"
$env:HELLO -eq $null
# Run dotenv file for a single script block
# the environment will clean itself when the script block completes
Invoke-Environment .env { $env:HELLO -eq 'WORLD' }
$env:HELLO -eq $null
Check here for more examples
- Clone this repo into a folder in your
$env:PSModulePath
- Run
Import-Module EnvUtils
Why not just use <insert-programming-language> implementation of dotenv?
dotenv and similar libraries, work well if you're only testing an application written in that language.
EnvUtils
gives you a bit more freedom over the dotenv
file loading, merging, overrides, etc.
Why not use PS-Dotenv?
PS-Dotenv is a PowerShell implementation of direnv, which you should check out if that is what you're after.
Use EnvUtils
when you do not want to automatically load dotenv
files and you want full
control over when the environment is overridden.