0

I'm trying to write a Powershell script to get the status from a HP RAID controller (using hpssacli.exe ctrl slot=1 ld all show detail and piping it into a file.

I just need to check whether Status: OK appears in the output. The problem is there are multiple strings that contain Status: OK

output.txt

Smart Array P410 in Slot 1
    array A
      Logical Drive: 1
         Size: 10.9 TB
         Fault Tolerance: 5
         Heads: 255
         Sectors Per Track: 32
         Cylinders: 65535
         Strip Size: 256 KB
         Full Stripe Size: 1024 KB
         Status: Interim Recovery Mode
         Caching:  Enabled
         Parity Initialization Status: Initialization Completed
         Disk Name: /dev/sda
         Mount Points: /storage 10.9 TB Partition Number 2
         OS Status: LOCKED
         Drive Type: Data
         LD Acceleration Method: Controller Cache

I was trying to run the command sls "Status: " .\output.txt but I receive 3 matches:

output.txt:13:         Status: Interim Recovery Mode
output.txt:15:         Parity Initialization Status: Initialization Completed
output.txt:19:         OS Status: LOCKED

Is there a way with Powershell to do a regex style match to only match where the string is not a character, followed by Status:?

0

You could match based on that string containing only spaces before your output using

Select-String "(^\s*)Status: " .\output.txt

or match exactly 9 spaces before the word Status.

 Select-String "(^\s{9})Status: " .\output.txt 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.