Skip to content

Instantly share code, notes, and snippets.

@PatrickLang
Created May 24, 2017 15:23
Show Gist options
  • Save PatrickLang/69567f35530c1b0306b71f16233668e7 to your computer and use it in GitHub Desktop.
Save PatrickLang/69567f35530c1b0306b71f16233668e7 to your computer and use it in GitHub Desktop.
PowerShell snippet for finding all Vagrantfiles under a path and showing the status

I've made the mistake of accidently removing VMs with Remove-VM or Hyper-V Manager that I originally created with Vagrant. This is a set of code snippets I'm using to help prevent that and make it easy to find all Vagrant created VMs, remove the ones I don't need, then delete the boxes.

$oldpwd = $pwd ; gci -r Vagrantfile | %{ cd $_.Directory ; Write-Output "Checking status at $pwd" ; vagrant.exe status } ; cd $oldpwd

Other things I still need to do:

  • Purge unused boxes
    • Figure out how Vagrant refcounts things, if at all.
  • Write something to walk Packer's cache so I can clean up unneeded ISOs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment