VMware Cloud Community
tpc8486
Contributor
Contributor

Identify Linked Clones in ESXI 6.5

Need help identifying linked clones in esxi 6.5 using powercli.

I currently have 30+ vm's that our linked clones are based off of. We use those vm's and make 800+ linked clones for testing our product.

I need to move the 30+ vm's to a new datastore and want to identity all the linked clones associated with those 30+ so I can remove the linked clones.

Any help would be much appreciated.

11 Replies
LucD
Leadership
Leadership

Does this help?

Listing all linked clones on your vCenter Server


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
tpc8486
Contributor
Contributor

I've been using that one for a couple of days now. The problem is that it shows results that are questionable.

I have seen vm's in the list that I can almost 100% guarantee aren't linked clones.

So I'm not sure what to do with the results.

0 Kudos
tpc8486
Contributor
Contributor

So the script outputs a really large list. Is there a way to identify the parent vm of that linked clone? Have them side by side in the output?

0 Kudos
LucD
Leadership
Leadership

Just double checked, and there might indeed be an issue in that code.

Let me see if I can find a working version, which would also list the parent VM.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
mibiras
Contributor
Contributor

We have same issue as tpc8486, that  script from http://www.vmdev.info/?p=546 didnt show only linked clones.

I d like to suggest to identify linked by finding VMs which DiskFile name dont match their VM name:

$vm.ExtensionData.Layout.Disk | %{$_.DiskFile | where {$_ -notmatch $vm.Name}}

Is it possible to add this to loop for each vm and filter only with not matching filenames?

I know this will not produce only linked clones but I think these results should be better than from www.vmdev.info/?p=546

0 Kudos
LucD
Leadership
Leadership

You would also be finding all VMs that have been renamed, but for which there hasn't been a svMotion yet.

There the VM's DisplayName will also be different from the VMDK names.

Perhaps a combination of the old conditions and your suggestion would be better.

Try something like this.
I'm very curious to see:

  • if it improves the success rate
  • which non-Linked Clones still get through

function Get-LinkedClone {

   #The following line is a fast replacement for:  $vms = get-vm args[0] | get-view

   if( $args[0] -eq $null ) {

      $vms = Get-View -ViewType VirtualMachine -Property Name,Summary,Config.Hardware.Device,Layout.Disk

   } else {

      $vms = Get-View -ViewType VirtualMachine -Property Name,Summary,Config.Hardware.Device,Layout.Disk -Filter @{Name = $args[0]}

   }

   $linkedClones = @()

   foreach ($vm in $vms) {

      $unshared = $vm.Summary.Storage.Unshared

      $committed = $vm.Summary.Storage.Committed

      $ftInfo = $vm.Summary.Config.FtInfo

    $vmdkNameDifferent = ($vm.Layout.Disk | %{$_.DiskFile[0] -notmatch $vm.Name}) -contains $true

      if ( ($unshared -ne $committed) -and (($ftInfo -eq $null) -or ($ftInfo.InstanceUuids.Length -le 1)) -and $vmdkNameDifferent){

         # then $vm is a linked clone.

         # Find $vm's base disks.

         $baseDisks = @()

         foreach ($d in $vm.Config.Hardware.Device) {

            $backing = $d.backing

            if ($backing -is [VMware.Vim.VirtualDeviceFileBackingInfo] -and $backing.parent -ne $null) {

               do {

                  $backing = $backing.parent

               } until ($backing.parent -eq $null)

               $baseDisks += $backing.fileName

            }

         }

         $linkedClone = new-object PSObject

         $linkedClone | add-member -type NoteProperty -Name Name -Value $vm.name

         $linkedClone | add-member -type NoteProperty -Name BaseDisks -Value $baseDisks

         $linkedClones += $linkedClone

      }

      #else { do nothing for VMs that are not linked clones }

   }

   $linkedClones | sort BaseDisks, Name

}

Get-LinkedClone 


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

mibiras
Contributor
Contributor

Script produces only this error:

Cannot index into a null array.

At C:\Tools\linked_clones.ps1:29 char:63

+ ... tensionData.Layout.Disk | %{$_.DiskFile[0] -notmatch $vm.Name}) -cont ...

+                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException

    + FullyQualifiedErrorId : NullArray

Problem of script from www.vmdev.info/?p=546 is that sometimes it doesn't identify base disk ($vm.Config.Hardware.Device.backing.parent is empty) - this is reason why I suggested $vm.ExtensionData.Layout.Disk which always has value.

And also condition ($unshared -ne $committed) is fullfilled for most of VMs, not only linked clones or FT

0 Kudos
LucD
Leadership
Leadership

Try replacing that line with

$vmdkNameDifferent = ($vm.ExtensionData.Layout.Disk | %{$_.DiskFile -notmatch $vm.Name}) -contains $true


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

mibiras
Contributor
Contributor

After that, few errors like bellow, csv report created but with same amount of VMs as before, so I think that condition for

$vm.ExtensionData.Layout.Disk | %{$_.DiskFile -notmatch $vm.Name}) -contains $true

dont work

parsing "*JANKECH_OS_X_10.8_4_EES6_Mac_fix (admin-mac-85.hq.eset.com) .254" - Quantifier {x,y} following nothing.

At C:\Tools\linked_clones.ps1:30 char:60

+ ... .ExtensionData.Layout.Disk | %{$_.DiskFile -notmatch $vm.Name}) -cont ...

+                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : OperationStopped: (:) [], ArgumentException

    + FullyQualifiedErrorId : System.ArgumentException

parsing "*JANKECH_OS_X_10.8_5_EES6_Mac_fix (admin-mac-166.hq.eset.com) .145" - Quantifier {x,y} following nothing.

At C:\Tools\linked_clones.ps1:30 char:60

+ ... .ExtensionData.Layout.Disk | %{$_.DiskFile -notmatch $vm.Name}) -cont ...

+                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : OperationStopped: (:) [], ArgumentException

    + FullyQualifiedErrorId : System.ArgumentException

parsing "*JANKECH_Win7_ERA5_EEA5" - Quantifier {x,y} following nothing.

At C:\Tools\linked_clones.ps1:30 char:60

+ ... .ExtensionData.Layout.Disk | %{$_.DiskFile -notmatch $vm.Name}) -cont ...

+                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : OperationStopped: (:) [], ArgumentException

    + FullyQualifiedErrorId : System.ArgumentException

0 Kudos
LucD
Leadership
Leadership

I forgot to add Layout.Disk to the Property parameter on both Get-View cmdlets.

I updated the code above, please try again.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

mibiras
Contributor
Contributor

I found another way how identify linked clones. According VMware Knowledge Base I modified commands to

find /vmfs/volumes/ \( -size -1500c \) -name *.vmdk -exec grep vmfs {} -H \; | grep 'parentFileNameHint=' > linkedlist.txt

sed s/:/'-->>'/ < linkedlist.txt >linkedlist2.txt

and it produces list of linked clones as we needed

But anyway thanks LucD.