VMware Cloud Community
GarTomlon
Enthusiast
Enthusiast

Return duplicate UUIDs

When we do a vSPhere replication between Datacenters, we end up with duplicate IDs.  We have a process where I can export the VM and IDS to a CSV.  This is a full export using the following command ( in a powershell script).  It works fine.  I then massage the data in Excel to return the dup ids.  How can I modify this exisitng command so that it exports only the records with dupe ids?

get-vm | get-view | select name,@{l="uuid";e={$_.config.instanceuuid}}|export-csv $csvfile

Thanks

0 Kudos
3 Replies
LucD
Leadership
Leadership

Try like this

Get-VM | select name,@{l="uuid";e={$_.ExtensionData.Config.InstanceUuid}}|

Sort-Object -Property uuid -Unique |

Export-Csv $csvfile


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

0 Kudos
ugnrdk
Contributor
Contributor

-Unique shows only unique UUIDs and removes duplicates from the file. How about getting only duplicates? Is that possible?

0 Kudos
LucD
Leadership
Leadership

The Group-Object cmdlet can help with that.

Something like this

Get-VM | select name,@{l="uuid";e={$_.ExtensionData.Config.InstanceUuid}}|
Group-Object -Property uuid |
where{$_.Group.Count -gt 1} |
Select @{N='Name';E={$_.Group.Name -join '|'}},Name |
Export-Csv $csvfile


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