When Visual Studio is installed it has special command prompts with tools in PATH variables such as VS2012 x86 Native Tools Command Prompt
I wrote similar scripts for PowerShell (inspired by this)
#requires -version 2
param(
[string] $version = "11.0"
)
$vsToolsPath = "${Env:ProgramFiles(x86)}\Microsoft Visual Studio $version\VC"
$setVariablesBatch = 'vcvarsall.bat'
if (!(Test-Path $vsToolsPath)) {
throw "Visual Studio $version tools path $vsToolsPath not found."
}
Push-Location "$vsToolsPath"
if (!(Test-Path $setVariablesBatch)) {
throw "$vsToolsPath\$setVariablesBatch batch not found."
}
cmd /c "$setVariablesBatch & set" | ForEach-Object {
if ($_ -match "=") {
$variablePair = $_ -split "="
$name = $variablePair[0]
$value = $variablePair[1]
Set-Item -Force -Path "ENV:\$name" -Value "$value"
}
}
Pop-Location
Write-Host "`nVisual Studio $version Command Prompt variables set." -ForegroundColor Yellow