arrays - Check if number is in multiple strings and label -


here output working with:

pool name:  pool 2 pool id:  1 luns:  1015, 1080, 1034, 1016, 500, 1002, 1062, 1041, 1046, 1028, 1009, 1054, 513, 1058, 1070, 515, 1049, 1083, 1020, 1076, 19, 509, 1057, 1021, 525, 1019, 518, 1075, 29, 23, 1068, 37, 1064, 506, 1024, 1026, 1008, 1087, 1012, 1006, 1018, 502, 1004, 1074, 1030, 1032, 39, 1014, 1005, 1056, 1044, 2, 1033, 1001, 16, 1061, 1040, 1045, 1027, 26, 1023, 1053, 1037, 1079, 512, 520, 1069, 1039, 514, 1048, 1082, 523, 508, 524, 517, 522, 1066, 1089, 1067, 529, 528, 1063, 505, 1081, 527, 1007, 1086, 1051, 1011, 1035, 1017, 501, 1003, 1042, 1073, 1085, 1029, 1010, 24, 1013, 1055, 1043, 1059, 52, 1071, 516, 1050, 1084, 1000, 1077, 1060, 1072, 510, 1022, 1052, 526, 1036, 1078, 511, 35, 519, 1038, 521, 1047, 507, 6, 1065, 1025, 1088, 503, 53, 1031, 504  pool name:  pool 1 pool id:  0 luns:  9, 3, 34, 10, 12, 8, 7, 0, 38, 27, 18, 4, 42, 21, 17, 28, 36, 22, 13, 5, 11, 25, 15, 32, 1  pool name:  pool 4 pool id:  2 luns: (this 1 empty) 

what store each 1 of "luns:" own variables (array?). take number , search in arrays, in example there three. if matches number example "34" program output your number in pool 1

i know how pull lun lines need regex expressions , know how compare results if statement lost combining 2 , more lost when thinking outputting correct "pool name".

edit should add total number of pools can change lun number lists.

convert output single string, replace colons equals signs , split string @ double line breaks, convert fragments objects using convertfrom-stringdata , new-object , split lun string array:

$data = ... | 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 

with can pool name of pool containing given lun this:

$pools | ? { $_.luns -contains 34 } | select -expand 'pool name' 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -