Marodr811
Contributor
Contributor

Script on ESXi

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?

0 Kudos
12 Replies
msripada
Virtuoso
Virtuoso

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

daphnissov
Immortal
Immortal

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.

Marodr811
Contributor
Contributor

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.

0 Kudos
MBreidenbach0
Hot Shot
Hot Shot

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).

0 Kudos
Marodr811
Contributor
Contributor

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?

0 Kudos
MBreidenbach0
Hot Shot
Hot Shot

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.

Marodr811
Contributor
Contributor

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

0 Kudos
MBreidenbach0
Hot Shot
Hot Shot

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

Marodr811
Contributor
Contributor

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

0 Kudos
jrodsguitar
Enthusiast
Enthusiast

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

}

Blog: https://powershell.house/
0 Kudos
Marodr811
Contributor
Contributor

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??

0 Kudos
jrodsguitar
Enthusiast
Enthusiast

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

Blog: https://powershell.house/
0 Kudos