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
}
}
}
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
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
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}}
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}}
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
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
Thank you LucD. That worked perfectly 🙂