Script to find duplicates in a row and combine the data in specific column

Looking for a script to find duplicates in a line like below...

"VM1', 'VM', 'LDEV', 'LDEV1', 'LDEV2', 'LDEV3', 'LDEV4', 'LDEV5', 'LDEV6 '.
'VM', 'VI-SVC-VM001', "0000ef ', ' '," "," "," "," ""
'VM', 'VI-SVC-VM001', "0000de ', ' '," "," "," "," ""
'VM', 'VI-SVC-VM002', "0000df ', ' '," "," "," "," ""
'VM', 'VI-SVC-VM002', "0000f0 ', ' '," "," "," "," ""

.. .and manipulate the data in the following:

"VM1', 'VM', 'LDEV', 'LDEV1', 'LDEV2', 'LDEV3', 'LDEV4', 'LDEV5', 'LDEV6 '.
"" 'VM', 'VI-SVC-VM001', '0000ef', "0000de ', ' ', ' '," "," ""
"" 'VM', 'VI-SVC-VM002', '0000df', "0000f0 ', ' ', ' '," "," ""

(Note: VM VI-SVC-VM001 object has two LDEVs him assigned 0000ef and 0000de)

There may be two, three, or n LDEVs attributed to each VM object. I guess I have to build a table and the "join-collections" script can't cut it on this one.

I have the process to follow, I just need to put it in a loop (note, data already sorted on the virtual computer object):

1 import-csv

2. read each line, matched VM object, copy each found LDEV and place it in the next LDEV along

3. remove the duplicate line

4. rinse, repeat until the end

Thank you.

It's a solution pleasant Luc. I didn't use the Group-Object cmdlet to solve this problem.

Now I can go to sleep without having to worry about this problem more.

Tags: VMware

Similar Questions

Maybe you are looking for