Select-string on the result of select-string?


i'm dealing large text file, has multiple matches data i'm looking for. able use combination of -context piped select-object -first getthe exact, 20 line section of text i'm interested in. 

i further select-string on result, never works. if get-member on the object, type microsoft.powershell.commands.matchinfo

example: $hba = get-content c:\hba-info.txt

$info = $hba | select-string -pattern "hba general information" -context 20 | select-object -first 1

$info

hba general information
 
  --------------------------------------------------------------------------------
  --------------------------------------------------------------------------------
  host name                         : hq1md17
  hba instance                      : 0
  hba model                         : qla2342
  hba description                   : qla2342/qla2342l (pci fc dual channel)
  hba id                            : 0-qla2342
  hba alias                         :
  hba port                          : 1
  port alias                        :
  node name                         : 20-00-00-e0-8b-19-03-0b
  port name                         : 21-00-00-e0-8b-19-03-0b
  port id                           : 00-00-00
  serial number                     : q41219
  driver version                    : stor miniport 9.1.7.16
  bios version                      : 1.42
  driver firmware version           : 3.03.25
  actual connection mode            : loop
  actual data rate                  : unknown

if try $info | select-string -pattern "bios version" returns nothing.

i tried $info.tostring() first, no help.

try this, run next select-string on $info:

 

$info = $hba | select-string -pattern "hba general information" -context 20 |

foreach-object {$_.line,$_.context.postcontext}

 

alternate solution

$info = $hba | select-string -pattern "hba general information" -context 20 | out-string


[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

server manager error: ADAM.events.xml could not be enumerated.

Cannot access Anywhere Access using domain name?

WMI Failure: Unable to update Local Resource Group