All Tools View Categories About Contact Privacy

.env to PowerShell Script Converter

Convert a .env file into a PowerShell $env:KEY script — correct quoting, three assignment styles.

Runs entirely in your browser — nothing is uploaded.

About .env to PowerShell Script Converter

On Windows, environment variables live in several worlds at once: the current process, the registry-backed user and machine stores, and the PowerShell provider. Hand-converting a .env into something that loads under PowerShell usually means writing $env:KEY = value lines by hand — and guessing how to quote a value that contains an apostrophe or a trailing backslash.

The .env to PowerShell Converter removes the guesswork. It parses your .env and emits ready-to-run PowerShell: $env:KEY = 'value', with every value single-quoted and embedded quotes doubled exactly the way the PowerShell parser wants. A style toggle switches to Set-Item Env:KEY provider syntax, or to [Environment]::SetEnvironmentVariable for persistent User or Machine scopes.

The output is deterministic, reviewable and safe to paste into a terminal or a .ps1 bootstrapping your service. Comments, blank lines and quoted .env values are handled, and nothing leaves your browser.

Features

  • PS-correct quoting: single quotes with doubled embedded quotes.
  • Three styles: $env:KEY, Set-Item Env:KEY, and SetEnvironmentVariable.
  • Persistent scopes: process defaults, or User/Machine via the registry API.
  • No interpolation: dollar signs and backticks stay literal inside single quotes.
  • Special chars: apostrophes, spaces, ampersands and slashes survive exactly.
  • Comment control: keep or strip comments from the source .env.
  • Duplicate detection: repeated keys are flagged with line numbers.
  • Copy or download: clipboard or a .ps1 file ready to run.
  • Private: all conversion happens in your browser.

How to Use

  1. Paste your .env content into the input box, or load the sample with tricky values.
  2. Pick an assignment style — $env:KEY, Set-Item, or persistent scope.
  3. Optionally keep comments or strip them from the output.
  4. Click Convert. The PowerShell script appears on the right.
  5. Review warnings such as duplicate keys above the output.
  6. Copy or download the .ps1 file and dot-source or run it.

Examples

Example 1 — Dev machine bootstrap. A Windows developer converts their .env into a .ps1 and runs it before lunch; every variable lands in their current PowerShell session for the local dev tooling.

Example 2 — CI on Windows runners. A build engineer sources the generated script in an Azure DevOps or GitHub Actions Windows job so node or dotnet processes see identical configuration.

Example 3 — Service user profile. An admin persists variables for the service account with the User scope, so a background service keeps a stable environment across sessions.

Example 4 — Registry-backed legacy app. A team migrating a legacy Windows service converts DATABASE_URL and API keys to Machine scope via SetEnvironmentVariable for the service launch.

Example 5 — Onboarding. New hires run the same generated bootstrap.ps1 and are configured in seconds without a wiki of manual steps.

Benefits

  • Guaranteed quoting: PowerShell-safe escaping every time.
  • Exact values: apostrophes and dollars round-trip correctly.
  • Right scope: process/session or persistent User/Machine.
  • Readable: deterministic, easy to review before running.
  • No registry surprises: session mode never touches the registry.
  • Private & free: browser-only conversion, no account.

Frequently Asked Questions

What does this tool do?
It reads a .env file of KEY=value lines and emits a PowerShell script with lines such as $env:DATABASE_URL = 'value'. Values are quoted the PowerShell way — single quotes with embedded quotes doubled — so nothing is interpreted.
Why use $env:KEY assignment?
$env:KEY = 'value' is the natural, scoped way to set an environment variable for the current PowerShell process. It never touches the registry and lasts for the session, which is exactly what most scripts need.
How are quotes handled?
Every value is wrapped in single quotes. A single quote inside the value is doubled (''), which is PowerShell's escape for literal quotes, so values like it's raining are preserved exactly.
Can I persist variables beyond the session?
Yes. The scope toggle can emit [Environment]::SetEnvironmentVariable('KEY', 'value', 'Machine') lines that persist system-wide, or the User scope for the current user only. Use with care — Machine scope modifies the registry.
Does it handle special characters?
Yes. Dollar signs, ampersands, backslashes and spaces are all safe inside single-quoted PowerShell strings, which disable expansion and interpolation.
Is my data uploaded?
No. Everything runs client-side in your browser. Nothing is sent to any server, stored or logged.
What style options exist?
Three assignment styles: $env:KEY = 'value' (session), Set-Item Env:KEY -Value 'value' (explicit provider syntax), and SetEnvironmentVariable for persistable scopes. A toggle also strips or keeps comments from the source .env.