I’ve been using psake as my build tool and running my builds on Appveyor. Now Appveyor runs with all the visual studio commands available on the path. When you install visual studio, It gives you a special cmd shell shortcut that loads you an environment with all the visual studio stuff available, which is cool. But not for PowerShell.

DISCLAIMER: I originally found this solution on this msdn blog, but tweaked it to work with Visual Studio 2013, and 64bit versions of windows. Since I kept changing machines and loosing my scripts I decided to blog about it so I knew where to look to find the code again.

With that out of the way, here is the code I add to my PowerShell $PROFILE:

#### Functions Used to Load VS Command Prompt #####
function Get-Batchfile ($file) {
    $cmd = "`"$file`" & set"
    cmd /c $cmd | Foreach-Object {
        $p, $v = $_.split('=')
        Set-Item -path env:$p -value $v
function VisualStudioVars()
    $version = "12.0"
    $key = "HKLM:SOFTWARE\Wow6432Node\Microsoft\VisualStudio\" + $version
    $VsKey = Get-ItemProperty $key
    $VsInstallPath = [System.IO.Path]::GetDirectoryName($VsKey.InstallDir)
    $VsInstallDir = [System.IO.Path]::GetDirectoryName($VsInstallPath)
    $VsToolsDir = [System.IO.Path]::Combine($VsInstallDir, "Tools")
    $vs120comntools = (Get-ChildItem env:VS120COMNTOOLS).Value    
    $batchFile = [System.IO.Path]::Combine($vs120comntools, "vsvars32.bat")
    Get-Batchfile $batchFile
###### Run at startup ######

This basically finds the cmd file vsvars32.bat for visual studio 2013(VS12.0) and loads the specified files to the environment path for this session. Now I have access to devenv.exe and other visual studio tools from PowerShell. For new versions of Visual Studio, just update the version number references and you’re golden. Note that if you are using a 32bit version of windows, remove the Wow6432Node from the key path, making it:

$key = "HKLM:SOFTWARE\Microsoft\VisualStudio\" + $version

Bonus content:

$env:path += ";" + (Get-Item "Env:ProgramFiles").Value + "\Git\bin"
$env:path += ";" + (Get-Item "Env:ProgramFiles").Value + "\nodejs"

This is a quick addition of git and node to my PowerShell so I can run these as well. Extend these as needed for other installed executables.

When setting up a new machine I also install ps-get and posh-git based on Phil Haack’s blog post. Check it out for the full instructions of what you need to do, but for my own reference and your second, third and twentieth time, use the following commands

# Set the execution policy to allow random scripts from the web
Set-ExecutionPolicy RemoteSigned
# install ps-get
(new-object Net.WebClient).DownloadString("http://psget.net/GetPsGet.ps1") | iex
# install posh-git
install-module posh-git

And that’s my PowerShell $PROFLE information. Hope this helps someone other than just me next time I set up a new development machine, or reinstall Windows.

2015-05-12 Update:

I use chocolatey to install other helpful components to my shell.

iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))

Some common tools I like to have installed are:

choco install -y paint.net
choco install -y autohotkey
choco install -y git
choco install -y gitpad
choco install -y gitextensions
choco install -y nuget.CommandLine
choco install -y github
choco install -y atom
choco install -y colorcop
choco install -y console2
choco install -y f.lux