The script below demonstrates how you can list VMs cloned from snapshots. It checks each VM to see if it has a parent snapshot by examining its disk’s parent disk. If the parent disk is a snapshot, it implies the VM was cloned from that snapshot.

# Connect to vCenter Server
$vcServer = 'your-vcenter-server'
Connect-VIServer -Server $vcServer -Credential (Get-Credential)

# Function to check if a VM is cloned from a snapshot
function Check-VMClonedFromSnapshot {
param (
[VMware.VimAutomation.ViCore.Impl.V1.Inventory.VirtualMachineImpl]$VM
)

$isClonedFromSnapshot = $false
$vmDisks = Get-HardDisk -VM $VM

foreach ($disk in $vmDisks) {
$diskInfo = $disk.ExtensionData.Backing
if ($diskInfo.Parent -ne $null) {
$parentDisk = Get-View -Id $diskInfo.Parent.VmSnapshot
if ($parentDisk -ne $null) {
$isClonedFromSnapshot = $true
break
}
}
}

return $isClonedFromSnapshot
}

# Get all VMs
$vms = Get-VM

# Check each VM and report if it is cloned from a snapshot
foreach ($vm in $vms) {
if (Check-VMClonedFromSnapshot -VM $vm) {
Write-Host "$($vm.Name) is cloned from a snapshot."
}
}

# Disconnect from vCenter Server
Disconnect-VIServer -Server $vcServer -Confirm:$false

Podcast also available on PocketCasts, SoundCloud, Spotify, Google Podcasts, Apple Podcasts, and RSS.

Leave a comment

The Podcast

Join Naomi Ellis as she dives into the extraordinary lives that shaped history. Her warmth and insight turn complex biographies into relatable stories that inspire and educate.

About the podcast