Created
August 15, 2015 09:28
-
-
Save seankearon/a7562ab10b37cf29c68f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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