Skip to content

Instantly share code, notes, and snippets.

@aggieben
Last active August 29, 2015 14:25
Show Gist options
  • Save aggieben/a893acf7fcaaed565a47 to your computer and use it in GitHub Desktop.
Save aggieben/a893acf7fcaaed565a47 to your computer and use it in GitHub Desktop.
# this is required
Import-Module pscx
# just drop this into your $profile, somewhere after the above import-module line
function With-Env (
[string[]]$vars,
[Parameter(Position=1)]
[scriptblock]$f
) {
Push-EnvironmentBlock
Foreach ($var in $vars)
{
$key,$val = $var -split "=",2
Set-Item -Path "env:$key" -value $val
}
Invoke-Command -ScriptBlock $f
Pop-EnvironmentBlock
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment