VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Check Duplicate VM across cluster

Hi,

How can I check the duplicate VM Names across two different clusters ? Please help!!

$vmTab = @{}
foreach($vm in Get-VM){
$vm | where {$_.Name} | %{
if($vmTab.ContainsKey($_.Name)){
Write-Host "Duplicate VM Found" $_.Name "in" $vm.Folder "and" $vmTab[$_.Name]
} else {
$vmTab[$_.Name] = $vm.Folder
}
}
}

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

And if you want his for all duplicate VMS, you could do

Get-VM |
Group-Object -Property Name |
Where {$_.Count -gt 1} |
ForEach-Object -Process {
    $_.Group |
    Select Name,
        @{N='Cluster';E={(Get-Cluster -VM $_).Name}},
        @{N='Folder';E={$_.Folder.Name}}
}


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

View solution in original post

0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

You could also do

Get-VM |
Group-Object -Property Name |
Where {$_.Count -gt 1} |
Select @{N='VM';E=$_.Name}


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

the below script shows just the VM Name, I would like to get the Cluster and Folder Names of all the duplicate VMs.

I tried as below but Cluster and Folder info shows blank

Get-VM |
Group-Object -Property Name |
Where {$_.Count -gt 1} |
Select @{N='VM';E={$_.Name}},
@{N='Cluster';E={Get-Cluster -VM $_}},
@{N='Folder';E={$_.Folder.Name}}

0 Kudos
Macleud
Enthusiast
Enthusiast
Jump to solution

Hi

Get-VM |
Group-Object -Property Name |
Where {$_.Count -gt 1} |
Select @{N='VM';E={$_.Name}},
@{N='Cluster';E={Get-Cluster -VM $_.Group}},
@{N='Folder';E={$_.Group.Folder.Name}}

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try like this

 

Get-VM |
Group-Object -Property Name |
Where {$_.Count -gt 1} |
Select @{N='VM';E={$_.Name}},
@{N='Cluster';E={(Get-Cluster -VM $_.Group[0]).Name}},
@{N='Folder';E={$_.Group[0].Folder.Name}}

 


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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

And if you want his for all duplicate VMS, you could do

Get-VM |
Group-Object -Property Name |
Where {$_.Count -gt 1} |
ForEach-Object -Process {
    $_.Group |
    Select Name,
        @{N='Cluster';E={(Get-Cluster -VM $_).Name}},
        @{N='Folder';E={$_.Folder.Name}}
}


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Thank you LucD. That worked perfectly 🙂

0 Kudos