0

File : https://drive.google.com/file/d/10GAlcA9PI-mFHUmACvC5CPbzjl3QLrwJ/view?usp=sharing

$data = import-csv .\vDisk.csv |where 'raw lun id' -NotLike ''|Group-Object -Property VM -ashashtable

I have vdisk extracted from rvtools and trying to group shared RDM by VM name, the output of the code is:

Name                           Value
----                           -----
MGTMKS1112M                    {@{VM=MGTMKS1112M; Powerstate=poweredOff; Template=False; Disk=Hard disk 7; Capacity MB=150; Raw=True; Disk Mode=independent_persistent; Thin=; Eagerly Scrub=; Split=; Wri...
PRDSKM1111M                    {@{VM=PRDSKM1111M; Powerstate=poweredOff; Template=False; Disk=Hard disk 5; Capacity MB=1,024; Raw=True; Disk Mode=independent_persistent; Thin=; Eagerly Scrub=; Split=; W...
MGTMKS1111M                    {@{VM=MGTMKS1111M; Powerstate=poweredOff; Template=False; Disk=Hard disk 11; Capacity MB=150; Raw=True; Disk Mode=independent_persistent; Thin=; Eagerly Scrub=; Split=; Wr...
PRDSKM1112M                    {@{VM=PRDSKM1112M; Powerstate=poweredOff; Template=False; Disk=Hard disk 5; Capacity MB=1,024; Raw=True; Disk Mode=independent_persistent; Thin=; Eagerly Scrub=; Split=; W...

I want the the output like below ashashtable or grouped object. because two nodes share the same raw lun ids. if this approach cant work. any alternate methods? please advice.


Name                      Value
----                      -----
MGTMKS1112M,MGTMKS1111M   {@{VM=MGTMKS1112M; Powerstate=poweredOff; Template=False; Disk=Hard disk 7; Capacity MB=150; Raw=True; Disk Mode=independent_persistent; Thin=; Eagerly Scrub=; Split=; Wri...
PRDSKM1112M,PRDSKM1112M   {@{VM=PRDSKM1112M; Powerstate=poweredOff; Template=False; Disk=Hard disk 5; Capacity MB=1,024; Raw=True; Disk Mode=independent_persistent; Thin=; Eagerly Scrub=; Split=; W...

1 Answer 1

1

You may provide a custom property to Group-Object in which to group on

$data = import-csv .\vDisk.csv |where 'raw lun id' -NotLike ''
$data | Group-Object -Property { $sub = $_.vm.substring(0,9); ($data.vm -match $sub |  Select-Object -Unique | Sort-Object) -join ", "} -ashashtable

Output something like this

    Name                     Value
----                     -----
MGTMKS1111M, MGTMKS1112M {@{VM=MGTMKS1111M; Powerstate=poweredOff; Template=False; Disk=Hard disk 11; Capacity MB=150; Raw=True; Disk Mode=independent_persistent; Thin=; Eagerly Scrub=; Split=; Write Through=; Level=normal; Shares=1,000; Reservation=0; L...
PRDSKM1111M, PRDSKM1112M {@{VM=PRDSKM1111M; Powerstate=poweredOff; Template=False; Disk=Hard disk 5; Capacity MB=1,024; Raw=True; Disk Mode=independent_persistent; Thin=; Eagerly Scrub=; Split=; Write Through=; Level=normal; Shares=1,000; Reservation=0; ...
Sign up to request clarification or add additional context in comments.

9 Comments

The name got trimmed because of substring (0..9). any other way i can have the duplicate reference name? Ex: MGTMKS1112M as duplicate ref for MGTMKS1111M. otherwise both in comma separated as single string. also i will need to enumerate the values later in function.
any other way, i can filter by VM and compare its values? main key is Raw lun mapping matching to VM name.
Updated my answer. Try that.
the above code output is different than your output is shown. can help to check.
Sorry, didn't have access to your csv file before. Updated once more to remove the duplicates by adding Select-Object -Unique
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.