0

Trying to get data from crystal disk text file, in order to sort through the data i need to find out how many disks there are, when doing this in regex101 it gets the data fine but when i move this over to powershell it does not stop at the blank like like id expect but keeps going all the way past it, am i missing something i cant seem to find any reason as to why (i did try matches 0 aswell btw)

here is the regex101 results

function NumberOfDisks{

$fileContent = $rawReport

$pattern = '(?ms) Disk List (.*?)\n$'

[regex]::matches($rawReport, $pattern)
$result = $Matches[1]

Display-Alert -Message $result

}

and this is the result from powershell

Groups   : {0, 1}
Success  : True
Name     : 0
Captures : {0}
Index    : 632
Length   : 12417
Value    :  Disk List ---------------------------------------------------------------
            (01) ST1000LM048-2E7172 : 1000.2 GB [0/0/0, pd1]
            (02) SAMSUNG MZVLB256HAHQ-00000 : 256.0 GB [1/1/0, sq] - nv
           
           ----------------------------------------------------------------------------
            (01) ST1000LM048-2E7172
           ----------------------------------------------------------------------------
                      Model : ST1000LM048-2E7172
                   Firmware : SDM1
              Serial Number : ZDEGC7GX
                  Disk Size : 1000.2 GB (8.4/137.4/1000.2/1000.2)
                Buffer Size : Unknown
                Queue Depth : 32
               # of Sectors : 1953525168
              Rotation Rate : 5400 RPM
                  Interface : Serial ATA
              Major Version : ACS-3
              Minor Version : ACS-3 Revision 3b
              Transfer Mode : SATA/600 | SATA/600
             Power On Hours : 1733 hours
             Power On Count : 815 count
                Temperature : 37 C (98 F)
              Health Status : Good
                   Features : S.M.A.R.T., APM, NCQ, GPL
                  APM Level : 8080h [ON]
                  AAM Level : ----
               Drive Letter : D:
           
           -- S.M.A.R.T. --------------------------------------------------------------
           ID Cur Wor Thr RawValues(6) Attribute Name
           01 _69 _64 __6 000000705251 Read Error Rate
           03 _99 _99 __0 000000000000 Spin-Up Time
           04 _99 _99 _20 0000000005ED Start/Stop Count
           05 100 100 _36 000000000000 Reallocated Sectors Count
           07 _78 _60 _45 0000043054AE Seek Error Rate
           09 _99 _99 __0 24E7000006C5 Power-On Hours
           0A 100 100 _97 000000000000 Spin Retry Count
           0C 100 100 _20 00000000032F Power Cycle Count
           B8 100 100 _99 000000000000 End-to-End Error
           BB 100 100 __0 000000000000 Reported Uncorrectable Errors
           BC 100 100 __0 000000000000 Command Timeout
           BD 100 100 __0 000000000000 High Fly Writes
           BE _63 _36 _40 000E2B130025 Airflow Temperature
           BF 100 100 __0 000000000003 G-Sense Error Rate
           C0 100 100 __0 00000000000C Power-off Retract Count
           C1 _84 _84 __0 0000000082F3 Load/Unload Cycle Count
           C2 _37 _64 __0 000C00000025 Temperature
           C5 100 100 __0 000000000000 Current Pending Sector Count
           C6 100 100 __0 000000000000 Uncorrectable Sector Count
           C7 200 200 __0 000000000000 UltraDMA CRC Error Count
           F0 100 253 __0 145900000335 Head Flying Hours
           F1 100 253 __0 00049D531417 Total Host Writes
           F2 100 253 __0 0005BBB519B7 Total Host Reads
           FE 100 100 __0 000000000000 Free Fall Protection
           
           -- IDENTIFY_DEVICE ---------------------------------------------------------
                   0    1    2    3    4    5    6    7    8    9
           000: 0C5A 3FFF C837 0010 0000 0000 003F 0000 0000 0000
           010: 2020 2020 2020 2020 2020 2020 5A44 4547 4337 4758
           020: 0000 0000 0000 5344 4D31 2020 2020 5354 3130 3030
           030: 4C4D 3034 382D 3245 3731 3732 2020 2020 2020 2020
           040: 2020 2020 2020 2020 2020 2020 2020 8010 4000 2F00
           050: 4000 0200 0200 0007 3FFF 0010 003F FC10 00FB 0110
           060: FFFF 0FFF 0000 0007 0003 0078 0078 0078 0078 0100
           070: 0000 0000 0000 0000 0000 001F 8F0E 0006 006C 0040
           080: 07F0 001F 746B 7D69 6163 7469 BC49 6163 017F 004E
           090: 004E 8080 FFFE 0000 D0D0 0000 0000 0000 0000 0000
           100: 6DB0 7470 0000 0000 0000 0000 6003 0000 5000 C500
           110: B67E 8218 0000 0000 0000 0000 0000 0000 0000 401E
           120: 401C 0000 0000 0000 0000 0000 0000 0000 0029 6DB0
           130: 7470 6DB0 7470 2020 0002 0140 0100 5000 3C06 3C0A
           140: 0000 003C 0000 0008 0000 0000 BDFF 0280 0000 0000
           150: 0008 0000 0000 0027 1028 8000 4000 0100 A500 8000
           160: 0000 0000 0000 0000 0000 0000 0000 0000 0003 0000
           170: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
           180: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
           190: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
           200: 0000 0000 0000 0000 0000 0000 3035 0000 0000 4000
           210: 0000 0000 0000 0000 0000 0000 0000 1518 0000 0000
           220: 0000 0000 107F 0000 0000 0000 0000 0000 0000 0000
           230: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
           240: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
           250: 0000 0000 0000 0000 0000 32A5
           
           -- SMART_READ_DATA ---------------------------------------------------------
                +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F
           000: 0A 00 01 0F 00 45 40 51 52 70 00 00 00 00 03 03
           010: 00 63 63 00 00 00 00 00 00 00 04 32 00 63 63 ED
           020: 05 00 00 00 00 00 05 33 00 64 64 00 00 00 00 00
           030: 00 00 07 0F 00 4E 3C AE 54 30 04 00 00 00 09 32
           040: 00 63 63 C5 06 00 00 E7 24 27 0A 13 00 64 64 00
           050: 00 00 00 00 00 00 0C 32 00 64 64 2F 03 00 00 00
           060: 00 00 B8 32 00 64 64 00 00 00 00 00 00 00 BB 32
           070: 00 64 64 00 00 00 00 00 00 00 BC 32 00 64 64 00
           080: 00 00 00 00 00 00 BD 3A 00 64 64 00 00 00 00 00
           090: 00 00 BE 22 00 3F 24 25 00 13 2B 0E 00 00 BF 32
           0A0: 00 64 64 03 00 00 00 00 00 00 C0 32 00 64 64 0C
           0B0: 00 00 00 00 00 01 C1 32 00 54 54 F3 82 00 00 00
           0C0: 00 00 C2 22 00 25 40 25 00 00 00 0C 00 00 C5 12
           0D0: 00 64 64 00 00 00 00 00 00 00 C6 10 00 64 64 00
           0E0: 00 00 00 00 00 00 C7 3E 00 C8 C8 00 00 00 00 00
           0F0: 00 00 F0 00 00 64 FD 35 03 00 00 59 14 34 F1 00
           100: 00 64 FD 17 14 53 9D 04 00 00 F2 00 00 64 FD B7
           110: 19 B5 BB 05 00 00 FE 32 00 64 64 00 00 00 00 00
           120: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
           130: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
           140: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
           150: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
           160: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 71
           170: 03 00 01 00 01 9C 02 00 00 00 00 00 00 00 00 00
           180: 00 00 00 00 D8 11 00 00 00 01 01 01 01 01 01 01
           190: 01 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00
           1A0: 00 00 00 00 03 00 00 00 91 6A 84 35 AD 05 00 00
           1B0: 00 00 00 00 01 00 60 00 17 14 53 9D 04 00 00 00
           1C0: B7 19 B5 BB 05 00 00 00 00 00 00 00 00 00 00 00
           1D0: 00 00 00 00 00 00 00 00 40 16 00 00 01 00 00 00
           1E0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02
           1F0: 00 00 00 00 00 00 00 00 00 00 03 18 00 00 00 61
           
           -- SMART_READ_THRESHOLD ----------------------------------------------------
                +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F
           000: 01 00 01 06 00 00 00 00 00 00 00 00 00 00 03 00
           010: 00 00 00 00 00 00 00 00 00 00 04 14 00 00 00 00
           020: 00 00 00 00 00 00 05 24 00 00 00 00 00 00 00 00
           030: 00 00 07 2D 00 00 00 00 00 00 00 00 00 00 09 00
           040: 00 00 00 00 00 00 00 00 00 00 0A 61 00 00 00 00
           050: 00 00 00 00 00 00 0C 14 00 00 00 00 00 00 00 00
           060: 00 00 B8 63 00 00 00 00 00 00 00 00 00 00 BB 00
           070: 00 00 00 00 00 00 00 00 00 00 BC 00 00 00 00 00
           080: 00 00 00 00 00 00 BD 00 00 00 00 00 00 00 00 00
           090: 00 00 BE 28 00 00 00 00 00 00 00 00 00 00 BF 00
           0A0: 00 00 00 00 00 00 00 00 00 00 C0 00 00 00 00 00
           0B0: 00 00 00 00 00 00 C1 00 00 00 00 00 00 00 00 00
           0C0: 00 00 C2 00 00 00 00 00 00 00 00 00 00 00 C5 00
           0D0: 00 00 00 00 00 00 00 00 00 00 C6 00 00 00 00 00
           0E0: 00 00 00 00 00 00 C7 00 00 00 00 00 00 00 00 00
           0F0: 00 00 F0 00 00 00 00 00 00 00 00 00 00 00 F1 00
           100: 00 00 00 00 00 00 00 00 00 00 F2 00 00 00 00 00
           110: 00 00 00 00 00 00 FE 00 00 00 00 00 00 00 00 00
           120: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
           130: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
           140: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
           150: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
           160: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
           170: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
           180: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
           190: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
           1A0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
           1B0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
           1C0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
           1D0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
           1E0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
           1F0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 92
           
           ----------------------------------------------------------------------------
            (02) SAMSUNG MZVLB256HAHQ-00000
           ----------------------------------------------------------------------------
                      Model : SAMSUNG MZVLB256HAHQ-00000
                   Firmware : EXD7201Q
              Serial Number : S444NX0M820032
                  Disk Size : 256.0 GB
                  Interface : NVM Express
                   Standard : NVM Express 1.2
              Transfer Mode : PCIe 3.0 x4 | PCIe 3.0 x4
             Power On Hours : 681 hours
             Power On Count : 819 count
                 Host Reads : 9864 GB
                Host Writes : 5732 GB
                Temperature : 39 C (102 F)
              Health Status : Good (98 %)
                   Features : S.M.A.R.T.,
2
  • have tried /r/n aswell but same result Commented Aug 6, 2022 at 19:19
  • 2
    Is $rawReport a single multiline string (got using Get-Content 'thefile' -Raw) or an array of strings you obtained with Get-Content 'thefile' (so, without -Raw). If an array, there will be no newlines to match on. If single multiline string, try with \r?\n Commented Aug 6, 2022 at 20:04

1 Answer 1

0

As well as Theo's comment about making sure you have a string with newlines in it, vs an array of lines without them, your code here:

[regex]::matches($rawReport, $pattern)
$result = $Matches[1]

only the operator -match sets the $Matches automatic variable. The .NET method call [regex]::matches() does not. So this code says "send all the matches to the pipeline, and then look for $result in a null variable". This should really be throwing an exception "Cannot index into a null array" unless you used -match earlier in the script.

You need $result = [regex]::matches($rawReport, $pattern) and then see where you are.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi, yes using the -Raw aswell have also tried using matches aswell, swapped to match when it didnt work $report = Get-Content $InfoFilePath -Raw
@G.Bushnell then I'll go with Theo's other suggestion, switching "\n$" for "\r\n\r\n".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.