anony
anony

Reputation: 26

Invoking command with custom environment variables

How do i do the equivalent of this bash style command invocation in powershell 1.0

output = `VAR1=value /path/someCommand`

In essence i need to manufacture a private & temporary $env:VAR1 for the purpose of invoking someCommand.

Upvotes: 0

Views: 331

Answers (2)

Keith Hill
Keith Hill

Reputation: 201592

You can set a process environment variable in PowerShell like so:

$env:VAR1 = 'value'

Then invoke the command:

/path/someCommand

Then remove the process env var:

remove-item Env:\Var1

Upvotes: 2

nathanchere
nathanchere

Reputation: 8098

Assuming you want to store the output of that command in var1:

$var1 = $_ | /path/someCommand

Assuming you want an alias so output will run that code whenever called:

Set-Alias output "$var = /path/someCommand"

Upvotes: 0

Related Questions