VMware vSphere

 View Only
Expand all | Collapse all

Script on ESXi

  • 1.  Script on ESXi

    Posted Mar 28, 2018 05:03 PM

    Hello I am a studen, currently installed ESXi to play with and also host several Vulnerable VMs.  I want to make a script to set the vms back to their initial state "recovery" or wipe and re install a fresh install at a set time.  Is this possible in ESXi.  I jave been trying to find documentation but have not been very successful or helpful.  Can anyone please help me or point me in the right direction?



  • 2.  RE: Script on ESXi

    Posted Mar 28, 2018 05:11 PM

    It may not be an actual or exact solution but you can take snapshot before making them vulnerable (fresh install of VM) and revert snapshot whenever you wanted to play again is an option.

    Thanks,

    MS



  • 3.  RE: Script on ESXi

    Posted Mar 28, 2018 05:28 PM

    I would agree with msripada​ here. The right approach would be to snapshot these VMs and use a scripted approach to revert them all. Alternatively, you could get the VMs to a point you wish, and then shut them down and convert the disks to independent non-persistent type. In this disk type, no changes will be persisted to the disk and all that's required is a reboot.



  • 4.  RE: Script on ESXi

    Posted Apr 11, 2018 08:12 PM

    Thank you all for all the help.  I have taken the snapshots of all the VMs I have in the ESXi 6.5.  I am trying to create a script to make a cron time schedule to revert them.  Would you guys be able to help me out or be able to tell me where I can find documentation on bash scripting in EXSi.  I have researched, watch YouTube videos but have not really found anything about scripting.   Thank you again for all your help and support.



  • 5.  RE: Script on ESXi

    Posted Apr 12, 2018 08:07 AM

    While ESXi does have a linux style busybox shell it isn't linux. ESXi console commands are there for configuration and troubleshooting but not really for 'operation' tasks.

    This can be done easily using PowerShell and VMwares PowerCLI package but that doesn't work with the 'free' license (it works with paid licenses and during the evaluation period).



  • 6.  RE: Script on ESXi

    Posted Apr 12, 2018 02:48 PM

    I have a paid License, now the eval period I am not understanding.  So if I can't write a script, is there a way for me to schedule the VMs to revert automatically?



  • 7.  RE: Script on ESXi

    Posted Apr 12, 2018 03:34 PM

    If you install ESXi without entering a license key you can test full Enterprise Plus features for 60 days. After these 60 days a license is required to power on VMs.

    There is a free Hypervisor license and there are paid Essentials/Essentials Plus/Standard/Enterprise Plus licenses.

    PowerCLI scripting does not work with the free Hypervisor license.

    PowerCLI can manage snapshots and you can run PowerCLI scripts via scheduler.

    Set-VM cmdlet can revert a VM to a snapshot.

    For example you could create a Windows or Linux VM with PowerShell Core + PowerCLI installed, write a script which reverts VMs to snapshot and run that script via OS scheduler.



  • 8.  RE: Script on ESXi

    Posted Apr 12, 2018 04:29 PM

    Thank you I will research PwoerCLI, do you know of any documentation by any chance.  Thank you very much for the all your help.



  • 9.  RE: Script on ESXi

    Posted Apr 12, 2018 04:37 PM

    There's a VMware PowerCLI community forum: VMware PowerCLI

    PowerCLI cmdlet reference is here: Online Documentation - Cmdlet Reference - VMware {code}

    PowerCLI is a PowerShell addon so you'll have to look into PowerShell. There are lots of books and other resources available. I started with the PowerShell book by Tobias Weltner.

    For info about PowerCLI check this book: Updated Book: PowerCLI Book 2nd Edition - VMware PowerCLI Blog - VMware Blogs



  • 10.  RE: Script on ESXi

    Posted Apr 12, 2018 04:55 PM

    Thank you, I am already on it.  You have been very helpful I appreciate it.



  • 11.  RE: Script on ESXi

    Posted Apr 12, 2018 07:48 PM

    Assuming you're still on that trial of Enterprise. You can do this:

    $names = ('VM1','VM2')

    $vms = get-vm $names

    foreach($vm in $vms){

    $snapShot = $null

    $snapShot = Get-Snapshot -VM $vm

    Set-VM $vm -Snapshot $snapShot -Confirm:$false

    }



  • 12.  RE: Script on ESXi

    Posted Apr 12, 2018 08:52 PM

    Thank you this is similar to something I found on forums.  How would I add the Timer to automate the process.  will $Days =ate the very beginning of it all work??



  • 13.  RE: Script on ESXi

    Posted Apr 12, 2018 09:34 PM

    You could create a Windows Scheduled tasks to run the script on an interval.