Mapping Replicas to View Desktop Pools

Identifying what replica is assigned to what desktop pool can be somewhat challenging in Horizon View. However, in some cases administrators need to know the object relationship to properly plan desktop and pool migrations across hosts or datastores.

The PowerShell script bellow produces a output that demonstrate this relationship.
Screen Shot 2013-03-14 at 2.04.33 PM
To execute save the script below as a .PS1 file in a View Connection Server with the VMware.VimAutomation.Core plug-in installed. The VMware.VimAutomation.Core plug-in is automatically installed with the VMware vSphere™ PowerCLI. Before executing the script you will need to change the vCenter server address at

[css language=”2=”] <p>Connect-VIServer -Server
Here is the script:

[css language=”2=”]
Add-PSSnapin VMware.VimAutomation.Core

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
$vms = Get-View -ViewType VirtualMachine
} else {
$vms = Get-View -ViewType VirtualMachine -Property Name,Summary,Config.Hardware.Device, -Filter @{Name = $args[0]}

$linkedClones = @()
foreach ($vm in $vms) {
Write-Host "The name of the vm is " $
$unshared = $vm.Summary.Storage.Unshared
$committed = $vm.Summary.Storage.Committed
$provisioned= ($vm.Summary.Storage.Commited + $vm.Summary.Storage.Uncommitted)

$ftInfo = $vm.Summary.Config.FtInfo

# This identifies if it is thin provisioned.
if ( ($unshared -ne $committed) -and (($ftInfo -eq $null) -or ($ftInfo.InstanceUuids.Length -le 1)) ){
# 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


if (($baseDisks -ne $null) -and -not $isReplica)
# $replica=$baseDisks[0].Substring($baseDisks[0].IndexOf("]") +2 , $baseDisks[0].IndexOf("/"))
$replicaDisk=$baseDisks[0].Substring(0, $slashpos)
$rbracketpos=$replicaDisk.IndexOf("]") +1

#$VMName = $vm | select -expandproperty name
#$VMUnshared = $vm | select -expandproperty storage | select -expandproperty perdatastoreusage | select -expandproperty Unshared
#— Get the disk space assigned

Write-Host "the VM " $ " has this many disks" $vm.Guest.disk.length
$totalDiskSpace = 0
$diskSpaceAssigned = 0

for ($iCount = 1;$iCount -le $vm.Guest.Disk.Count; $iCount++)
$diskSpaceAssigned = [math]::Round($vm.Guest.Disk[$index].Capacity / 1GB)
#$Details | Add-Member -Name "Disk$($DiskNum)FreeSpace(GB)" -MemberType NoteProperty -Value ([math]::Round($disk.FreeSpace / 1GB))
$totalDiskSpace=$totalDiskSpace + $diskSpaceAssigned
$GuestTotalDiskSpace = $totalDiskSpace
$uncommittedGB= [math]::round($uncommitted/1GB,2)
$VMUnsharedGB = [math]::round($unshared/1GB,2)
# $VMUsed = $vm | select -expandproperty storage | select -expandproperty perdatastoreusage | select -expandproperty Committed
$VMUsedGB = [math]::round($committed/1GB,2)
$linkedClone = new-object PSObject
$linkedClone | add-member -type NoteProperty -Name Name -Value $
$linkedClone | add-member -type NoteProperty -Name Parent -Value $replica

$linkedClone | add-member -type NoteProperty -Name DiskCount -Value $vm.Guest.Disk.Count

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

$linkedClone | add-member -type NoteProperty -Name UniqueDiskUsedGB -Value $VMUnsharedGB
$linkedClone | add-member -type NoteProperty -Name VMCombinedStorageGB -Value $VMUsedGB
$linkedClone | add-member -type NoteProperty -Name GuestTotalDiskSpace -Value $GuestTotalDiskSpace

$linkedClones += $linkedClone
#else { do nothing for VMs that are not linked clones }

Write-Host $vm.Name "Not a Linked Clone" -ForegroundColor ‘Red’
$stan = $linkedClones | sort Name, DiskCount, VMCombinedStorageGB, UsedStorageGB, GuestTotalDiskSpace
$stan | ConvertTo-Html > c:\temp\output.html

Connect-VIServer -Server
Thanks VMware EUC Senior Consultant Hans Bader for sharing the script with us. However, please not that I have not heavily tested the script and if you find any issues or want to improve it please share with us.
This article was first published by Andre Leibovici (@andreleibovici) at  


Skip to comment form

    • Norbert on 10/11/2013 at 2:31 am

    love this script, thanks alot 🙂

  1. Thanks Andre! Only other thing is I had to change the output file otherwise I got errors bc C:\temp doesn’t exist on my desktop.

    • Jaime on 11/17/2015 at 7:45 am

    Andre, I had followed the instructions to the “t” and I ran it and does not do anything, the last two lines in the script does not make any sense:

    Connect-VIServer -Server

    • John on 10/28/2016 at 8:56 am

    Awesome script, thanks for posting it!!

Leave a Reply