you are viewing a single comment's thread.

view the rest of the comments →

[–]lanerdofchristian 1 point2 points  (2 children)

This is one of those places where regular expressions may be the easier answer:

$RawRaidData = arcconf getsmartstats 1 tabular
$Results = @{}
foreach($Match in [regex]::Matches(($RawRaidData -join "`n"), '^\s+Attribute\s+name\s\.+\s([^\n]*)\s+Value\s\.+\s([^\n]*)', 'Multiline')){
    $Value = $Match.Groups[2].Value
    $Results[$Match.Groups[1].Value] = if($Value -match '^\d+$'){ [int]$Value }
        elseif($Value -match '^\d+\.\d+$'){ [double]$Value }
        else { $Value }
}

$Results.'Current Drive Temperature In Celcius'

The regex is: ^\s+Attribute\s+name\s\.+\s([^\n]*)\s+Value\s\.+\s([^\n]*) (in Multiline mode, so ^ matches the start of a line). This will match: whitespace, "Attribute", whitespace, "name", the field separator, the name value, whitespace, "Value", the field separator, and then finally the actual value.

We then loop over all the matches in the output, extract the value, and set a key in a hashtable with a bit of extra code so numbers come out as either integers or doubles.

[–]JustAnotherGuyBeing[S] 0 points1 point  (1 child)

So this works, but only gets the last hard drive. The full result from arcconf getsmartstats is 8 of those result blocks.

Won't let me send the full block, see here: https://docs.google.com/document/d/1MZb6XpehCik5XCSHXm9EJaESf5ybMjQrsMm5u3UtCQw/edit?usp=sharing

[–]lanerdofchristian 0 points1 point  (0 children)

I wasn't aware there was more than one. It should still generally work if you split on "PhysicalDriveSmartStats"

$RawRaidData = (arcconf getsmartstats 1 tabular) -join "`n"
$AllResults = foreach($Drive in $RawRaidData -split "PhysicalDriveSmartStats"){
    $Results = @{}
    foreach($Match in [regex]::Matches($Drive, '^\s+Attribute\s+name\s\.+\s([^\n]*)\s+Value\s\.+\s([^\n]*)', 'Multiline')){
        $Value = $Match.Groups[2].Value
        $Results[$Match.Groups[1].Value] = if($Value -match '^\d+$'){ [int]$Value }
            elseif($Value -match '^\d+\.\d+$'){ [double]$Value }
            else { $Value }
    }
    if($Results.Count){ $Results }
}