Skip to main content

Extracting Snapshots from our working Base VMs

When just getting started building an ESXi infrastructure, it is helpful to only have to build the base virtual machine once even though we might not be in a position to create a clone of it before vcenter is installed. The following powercli presumes that somewhere you took a powered off "Base" snapshot of a virtual machine that you subsequently modified to build a domain controller or possibly an xubuntu management box. Once vcenter is installed we can extract that base vm with just a little bit of PowerCLI. Ready?

The process outlined in a the code snippit creates a linked clone from the original and then a full clone from the linked clone, it is convoluted but it works well.

server.2019.base is currently my domain controller and xubuntu.20.04.base is my management system

image-20221217171236748

#Connect
$vserver="vcenter.range.local"
Connect-VIServer($vserver)
#Source VM
$vm=Get-VM -Name server.2019.base
$snapshot = Get-Snapshot -VM $vm -Name "Base"
$vmhost = Get-VMHost -Name "esxi1.range.local"
$ds=Get-DataStore -Name BASEVM
$linkedname = "{0}.linked" -f $vm.name
#Create the tempory VM
$linkedvm = New-VM -LinkedClone -Name $linkedName -VM $vm -ReferenceSnapshot $snapshot -VMHost $vmhost -Datastore $ds
#Create the Full VM
$newvm = New-VM -Name "server.2019.base.v2" -VM $linkedvm -VMHost $vmhost -Datastore $ds
#A new Snap Shot
$newvm | new-snapshot -Name "Base"
#Cleanup the temporary linked clone
$linkedvm | Remove-VM

image-20221218164633976

The following shows a successful run with our other VM

image-20221218171128417