Last active
January 13, 2022 16:06
-
-
Save nitrocode/2b0e4816d41cfbd7b092 to your computer and use it in GitHub Desktop.
Export all VMs on an ESX server using the ovftool
This file contains hidden or 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
| #!/bin/bash | |
| # This script will export all your VMs from an ESX server using the ovftool | |
| # - Provide the esx ip, esx user, and esx pass | |
| # - Make sure the password follows unicode conventions e.g. the @ sign is %40 | |
| # - Also make sure all VMs are reverted and shutdown | |
| # - This does not export snapshots | |
| # How it works: | |
| # | |
| # runs vim-cmd to get all the vms on the esx server | |
| ## filters out the first line to remove the titles | |
| ## filters out the 2nd column | |
| # for each of the preceding line's output, save the output to variable $vm | |
| ## use $vm as the name of the vm to export | |
| ## use $vm as the name of the ova to export to locally | |
| esx="10.59.1.105" | |
| esxuser="root" | |
| esxpass="password" | |
| # ssh root@10.59.1.105 "vim-cmd vmsvc/getallvms | tail -n+2 | awk '{print \$2}'" | while read vm; do echo "Exporting $vm..."; ovftool --noSSLVerify "vi://root:%40utom%40tion@10.59.1.105/$vm" $vm.ova; done; | |
| # ssh $esxuser@$esx "vim-cmd vmsvc/getallvms | tail -n+2 | awk '{print \$2}'" | while read vm; do echo "Exporting $vm..."; ovftool --noSSLVerify "vi://$esxuser@$esx/$vm" $vm.ova; done; | |
| ssh $esxuser@$esx "vim-cmd vmsvc/getallvms | tail -n+2 | awk '{print \$2}'" | while read vm; do | |
| echo "Exporting $vm..."; | |
| ovftool --noSSLVerify "vi://$esxuser:$esxpass@$esx/$vm" $vm.ova; | |
| done; | |
| echo "Finished" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment