0

Am novice with PS Scripting and am looking for assistance for the below requirement for Dell Servers:

Read the System Event logs for Event ID 2048, Extract the Time the even was generated, Physical Disk Number on specific RAID controller.

For Example:

Get-WinEvent -FilterHashtable @{logname='System' ; id=2048} -MaxEvents 1

Returns Output:

ProviderName: Server Administrator

TimeCreated Id LevelDisplayName Message 
----------- -- ---------------- ------- 
3/26/2018 1:18:51 AM 2048 Error Device failed: Physical Disk 0:0:13 Controller 0, Connector 0

I want to extract the disk and controller numbers along with the date in the following format:

**Disk-Failure, Date = 3/26/2018 1:18:51 AM , Physical Disk Number = 0:0:13 , Controller = 0 , Connector = 0**

Please assist.

Thank You.

1
  • 1
    Can you provide what you have tried so far? There are lots of similar text search/replacement questions here and on other sites. Keywords: replace, match, regex (if you want), string format Commented Mar 30, 2018 at 16:36

1 Answer 1

1

A regex might be a good way to approach this. It can select items out of the message property.

[regex]$rx = '.*Physical Disk (?<pd>.*) Controller (?<ctrl>.*), Connector (?<conn>.*).*'

Get-WinEvent -FilterHashtable @{logname='System' ; id=2048} -MaxEvents 1 |
    ForEach-Object {
        $r = $rx.Match($_.Message)
        $pd = $r.Groups['pd'].Value
        $ctrl = $r.Groups['ctrl'].Value
        $conn = $r.Groups['conn'].Value

        %{[string]::Format('**Disk-Failure, Date {0} , Physical Disk Number = {1} , Controller = {2} , Connector {3}', `
            $_.TimeCreated, $pd, $ctrl, $conn)}
    }

To test this, since I do not have any disk failures on my machine, I created an object with the properties that Get-WinEvent presented.

$properties = @{'TimeCreated'='3/26/2018 1:18:51 AM';
                'Id'=2018;
                'LevelDisplayName'='Error';
                'Message'= 'Device failed: Physical Disk 0:0:13 Controller 0, Connector 0'}
$object = New-Object -TypeName PSObject -Prop $properties
Sign up to request clarification or add additional context in comments.

Comments

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.