July 2026

How to Set an Environment Variable with PowerShell in Windows 11

Setting an environment variable with PowerShell lets you define configuration values that programs can read, either temporarily for a session or permanently. Windows 11’s PowerShell handles both cases with clear syntax.

The Command

[Environment]::SetEnvironmentVariable("MyVar", "MyValue", "User")

What It Does

This creates a permanent environment variable named MyVar with the value MyValue, stored at the User level so it persists across sessions for your account. The third argument, “User”, sets the scope; “Machine” would make YYGACOR Resmi it system-wide but requires administrator rights. Once set, programs and future sessions can read this variable.

When You’d Use This

This is useful when configuring tools that read environment variables, setting up a development environment, or defining values you want available to programs and future sessions. Choosing User or Machine scope controls whether the variable applies to just your account or the whole system, which matters when a tool needs the setting available system-wide or only for you.

Useful Variations

For a temporary variable in the current session only, `$env:MyVar = “MyValue”` is simpler and disappears when the session ends. To set a machine-wide variable, use “Machine” as the scope in an administrator session. To remove a variable, set its value to an empty string or `$null` at the same scope.

If It Doesn’t Work

If the new variable does not show up, remember permanent variables do not appear in already-open sessions, so open a new terminal to see them. Setting a Machine-scope variable requires administrator rights, so use an elevated session for that, while User scope needs no elevation. For a temporary variable in the current session only, `$env:Name = “value”` is simpler and does not persist.

Good to Know

Permanent variables set at the User or Machine level do not appear in already-open sessions until those are restarted, so open a new terminal to see the change. Setting a Machine-scope variable requires administrator rights, while User-scope variables affect only your account and need no elevation.

Putting It Together

The command shown may look dense at first, but it breaks down into clear parts once you have used it a few times. As part of gathering facts about your hardware and Windows setup, this command saves you from digging through settings screens. Together with the others in this area, it lets you document a system’s full configuration or answer a specific specification question in seconds from the terminal. Like anything in the terminal, the real value comes from trying it on your own system and adapting the variations above to what you actually need, so it is worth experimenting with in a safe, low-stakes situation before relying on it in a script or during troubleshooting. Keeping a note of the commands you find most useful, along with the variations that fit your workflow, turns scattered one-off tricks into a personal reference you can draw on whenever a similar task comes up again.

404 Not Found

Not Found

The requested URL was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.