shaik abdul
shaik abdul

Reputation: 39

PowerShell hashtable filtering values in array

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...

Upvotes: 0

Views: 136

Answers (1)

Daniel
Daniel

Reputation: 5114

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; ...

Upvotes: 1

Related Questions