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
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
-Unique shows only unique UUIDs and removes duplicates from the file. How about getting only duplicates? Is that possible?
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