PowerShell: Setting an environment variable for a single command only

Generally, it would be better to pass info to the script via a parameter rather than a
global (environment) variable. But if that is what you need to do you can do it this way:

$env:FOO = 'BAR'; ./myscript

The environment variable $env:FOO can be deleted later like so:

Remove-Item Env:\FOO

Leave a Comment