Skip to content

Instantly share code, notes, and snippets.

@seankearon
Created August 15, 2015 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seankearon/a7562ab10b37cf29c68f to your computer and use it in GitHub Desktop.
Save seankearon/a7562ab10b37cf29c68f to your computer and use it in GitHub Desktop.
function Invoke-Environment {
# Source: http://stackoverflow.com/a/4385011/2608
# and https://github.com/nightroman/PowerShelf/blob/master/Invoke-Environment.ps1
param
(
[Parameter(Mandatory=1)][string]$Command,
[switch]$Output,
[switch]$Force
)
$stream = if ($Output) { ($temp = [IO.Path]::GetTempFileName()) } else { 'nul' }
$operator = if ($Force) {'&'} else {'&&'}
foreach($_ in cmd /c " $Command > `"$stream`" 2>&1 $operator SET") {
if ($_ -match '^([^=]+)=(.*)') {
[System.Environment]::SetEnvironmentVariable($matches[1], $matches[2])
}
}
if ($Output) {
Get-Content -LiteralPath $temp
Remove-Item -LiteralPath $temp
}
}
# Configures the environment as per the VS Developer Command Prompt.
function As-VSPrompt {
# VS 2013
Invoke-Environment '"%VS120COMNTOOLS%\vsvars32.bat"'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment