arrays - Add new property based on a different objects property -


i'm trying search through 1 column in each row of table. add value row based on number being search.

this code produces table:

$lunssummary = ($ny_luns)  -split '\s+(?=logical unit number)' | foreach {     $stringdata = $_.replace(':','=')     new-object psobject -property $(convertfrom-stringdata $stringdata) }  $lunssummary |     select 'name','logical unit number','state','lun capacity(megabytes)','lu storage groups' |     format-table -autosize 

enter image description here

then have code can search using "logical unit number" , produce desired output. in example -contains 1029 above screenshot.

$data = $luns_in_pools | out-string $pools = $data -replace ': +','=' -split "`r`n`r`n" |   % { new-object -type pscustomobject -property (convertfrom-stringdata $_) } |   select -property *,@{n='luns';e={$_.luns -split ', '}} -exclude luns  $pools | ? { $_.luns -contains 1029 } | select -expand 'pool name' 

which produces in case "pool 2". result can pool 1-99.

enter image description here

i want combine these 2 codes search every "logical unit number" , add result end of table in 5th section/column "pools".

edit

as requested, raw data:

desired output: (pool obtained "logical unit number") enter image description here

edit 2

this closest correct far, prints same pool result every time.

$lunssummary =  ($ny_luns)  -split '\s+(?=logical unit number)' |  foreach { $stringdata =            $_.replace(':','=')           new-object psobject -property  $(convertfrom-stringdata $stringdata) }   $data = $luns_in_pools | out-string $pools = $data -replace ': +','=' -split "`r`n`r`n" |   % { new-object -type pscustomobject -property (convertfrom-stringdata $_) } |   select -property *,@{n='luns';e={$_.luns -split ', '}} -exclude luns  $poolproperty = @{label="pool";expression={$pools | ? { $_.luns -contains       [int]$_.'logical unit number'} | select -expand 'pool name'}} $lunssummary | select 'name','logical unit number','state','lun      capacity(megabytes)','lu storage groups',$poolproperty 

if check output of $pools | ? { $_.luns -contains [int]$_.'logical unit number'} | select -expand 'pool name'

i see 1 result. i'm thinking maybe has looped how?

from guess of need 1 more calculated property on end there 'pool'. have, , tested, logic. need implement it.

$poolproperty = @{label="pool";expression={     $lunid = $_.'logical unit number';     $pools | where-object{$_.luns -contains $lunid} |          select-object -expand 'pool name'} } $lunssummary | select 'name','logical unit number','state','lun capacity(megabytes)','lu storage groups',$poolproperty 

we take logical unit number of current item in pipeline , save can start extract match $pools object. long luns exclusive return 1 pool name.

the above should work changed how $pools created matched logic of $lunssummary. used here-strings raw data paste bin.

$lunssummary = ($ny_luns)  -split '\s+(?=logical unit number)' |  foreach { $stringdata =            $_.replace(':','=')           new-object psobject -property  $(convertfrom-stringdata $stringdata) }   $pools = ($luns_in_pools | out-string) -split '\s+(?=pool name)' | foreach-object{     new-object -type pscustomobject -property (convertfrom-stringdata ($_ -replace ":","=")) |     select -property *,@{n='luns';e={$_.luns -split ',\s*'}} -exclude luns }  $poolproperty = @{label="pool";expression={     $lunid = $_.'logical unit number';     $pools | where-object{$_.luns -contains $lunid} |          select-object -expand 'pool name'} } $lunssummary | select 'name','logical unit number','state','lun capacity(megabytes)','lu storage groups',$poolproperty 

looks $luns_in_pools newline delimited string. piping out-string cleaned remove newlines , allow regex/convertfrom-stringdata work.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

Kivy: Swiping (Carousel & ScreenManager) -

jdbc - Not able to establish database connection in eclipse -