Skip to content

Instantly share code, notes, and snippets.

@objectx
Last active December 15, 2015 12:19
Show Gist options
  • Save objectx/5259879 to your computer and use it in GitHub Desktop.
Save objectx/5259879 to your computer and use it in GitHub Desktop.
vagrant starter written in PowerShell.
$script_dir = Split-Path -parent $MyInvocation.MyCommand.Path
$embedded_dir = Join-Path $(Split-Path -parent $script_dir) "embedded"
$ruby = Join-Path $embedded_dir "bin/ruby"
$vagrant_executable = Join-Path $embedded_dir "gems/bin/vagrant"
$processStartInfo = New-Object System.Diagnostics.ProcessStartInfo
$processStartInfo.FileName = $ruby
$processStartInfo.WorkingDirectory = (Get-Location).Path
$processStartInfo.UseShellExecute = $false
$processStartInfo.Arguments = "`"$vagrant_executable`" $Args"
# Write-Host -Foreground Cyan $processStartInfo.Arguments
$env = $processStartInfo.EnvironmentVariables
# Export gem paths so that we use the isolated gems.
$env["GEM_PATH"] = Join-Path $embedded_dir "gems"
$env["GEM_HOME"] = Join-Path $embedded_dir "gems"
$env["GEMRC"] = Join-Path $embedded_dir "etc/gemrc"
# Export an enviromental variable to say we're in a Vagrant
# installer created environment.
$env["VAGRANT_INSTALLER_ENV"]="1"
$env["VAGRANT_INSTALLER_EMBEDDED_DIR"]=$embedded_dir
$env["PATH"] = "$embedded_dir\bin;$embedded_dir\gnuwin32\bin;$env:PATH"
$process = [System.Diagnostics.Process]::Start($processStartInfo)
$process.WaitForExit();
exit $process.ExitCode
@objectx
Copy link
Author

objectx commented Apr 23, 2013

As vagrant 1.2.1, system was installed under "C:\Program Files (x86)\HashiCorp\Vagrant". So we need apropriate quoting.

Please tell me how to obtain the vagrant installation path. Installer does not record it in HKLM:\Software...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment