Using PowerShell To Get Physical Disk Info On A Dell Server

This post is a bit lengthy. To skip past the preamble click here, and to go straight to the full script, click here.

A couple of months ago, I was skimming through the WMI/CIM classes that are installed on Dell servers if you use their OMSA (Open Managed Server Administrator) software. If you’re not familiar, CIM stands for Common Information Model and is a standardised way of representing information about a system, used on most platforms.

OMSA adds a lot of useful information to the CIM data and you can find out almost anything about the hardware. One ommision however, is the physical and virtual disk info. This is available through the OMSA web app, so I was a little bit puzzled about this. After delving into OMSA a bit more with Google, I found out that there is a command line utility that lets you pull this data in Command Prompt on Windows, or your favorite Linux shell.

This was fine, but running the command returned far more detail than I wanted and it was all text. Short of running some bash commands that i’m less than familiar with, or performing some batch file gymnastics to sort through the data, this was no good to me. I wanted to use PowerShell…

…and so, I did.

The Process

I start by using a variable to store the output of the omreport.exe command. In PowerShell, the & signifies that you want to run a non-PowerShell command.

$omsa = & "C:\Program Files\Dell\SysMgt\oma\bin\omreport.exe" storage pdisk controller=0

The output of this command, and subsequently the variable looks like this

omsaoutput

From this, I can immediately see a couple of things.

    I need a way to count the number of disks, I should be able to count the number of ID lines. This will be $diskCount
    I can ignore the first 3 lines since I only care about the disks, not the controller model. Since the first line is #0, I’ll start at line #3
    There is a blank line between each disk that I will need to skip
    You can’t see it in the shot, but each disk section has the same number of lines. We’ll call that $lineCount.
    Looking at the data, I have a seemingly nice way of separating the name and value of each line with the colon (:) – _but there’s a gotcha_.

Now, lets play with numbers.

# Count the number of disks
$diskCount = $omsa | Where {$_ -like 'ID*'} | Measure-Object | Select-Object -ExpandProperty Count

# Count the number of lines in the first disk
$lineCount=0
for($i=3;$i -lt $omsa.Count; $i++){
if($omsa[$i] -ne ''){
$lineCount++
}
else{
break
}
}

In this instance, I have 4 disks, and each disk has 37 lines. Now I need to set start and finish lines for the first disk.

$lineStart = 3 # First line of first disks information
$lineEnd = $lineCount + 2 # Last line of first disks information

From here a couple of things will happen.

    I’ll create an empty array to hold all of my disks
    I’ll use another For Loop, combined with a Foreach loop to work through each disk, and each line.
    At the start of the For Loop, I’ll create a new empty object to hold the disk information
    In the For Loop, I increment the $lineStart by 1 for each disk to skip the blank space, and get the current disks finish line by adding $lineStart and $lineCount.

I’ll use a method called Split to separate the lines into key/value pairs at the colon (:) and Trim to remove excess spaces
Gotcha – The split will cause a problem with the ID and Name values, as they also contain colons – I’ll have to replace these first.

    Then I’ll store the key/value pairs in the object and finally, add the object in the array
# Empty array to store all disks in
$disks = New-Object System.Collections.ArrayList

for($i=0;$i -lt $diskCount;$i++){
# Empty object to store disk info
$disk = new-object -TypeName psobject

foreach($j in $omsa[$lineStart..$lineEnd]){
# Replace colons with dashes
if($j -match "0:0:$i"){
$j = $j -replace "0:0:$i","0-0-$i"
}

# Split lines into Key/Value pairs, remove excess spaces
$name = $j.split(':')[0].trim().replace(' ','')
$value = $j.split(':')[1].trim()
$disk | Add-Member -MemberType NoteProperty -Name $name -Value $value
}

# Add disk object to disks array
[void]$disks.Add($disk)

# Increment start and finish lines for next disk
$lineStart = $lineEnd + 2
$lineEnd = $lineStart + ($lineCount - 1)
}

The result now looks similar to the output from OMSA, minus the top 3 lines, excess spaces and with dashes replacing some colons.

powershelloutput

But there is one key difference – Instead of text, we have objects. If we pipe the $disk object to Get-Member, we can see it’s properties.

diskproperties

Now we can sort, select and measure by property name and filter easily with Where-Object.

finaloutput

I hope you find this useful.

$diskCount = $omsa | where {$_ -like 'ID*'} | measure | select -ExpandProperty Count
$lineCount=0

for($i=3;$i -lt $omsa.Count; $i++){
if($omsa[$i] -ne ''){
$lineCount++
}
else{
break
}
}

$lineStart = 3
$lineEnd = $lineCount + 2
$disks = New-Object System.Collections.ArrayList
for($i=0;$i -lt $diskCount;$i++){
$disk = new-object -TypeName psobject
foreach($j in $omsa[$lineStart..$lineEnd]){
if($j -match "0:0:$i"){
$j = $j -replace "0:0:$i","0-0-$i"
}
$name = $j.split(':')[0].trim().replace(' ','')
$value = $j.split(':')[1].trim()
$disk | Add-Member -MemberType NoteProperty -Name $name -Value $value
}
[void]$disks.Add($disk)
$lineStart = $lineEnd + 2
$lineEnd = $lineStart + ($lineCount - 1)
}
$disks | Where-Object -Property State -eq Online | Select-Object -Property ID,Status,FailurePredicted,SerialNo.

6 thoughts on “Using PowerShell To Get Physical Disk Info On A Dell Server

  1. I have disk on two controllers, 0:1:8 . Also 16 Disks. Anyway you can fix this to understand more from the ID and Name. I will continue to play with it and post if I fix it first

    Like

  2. Great script works perfect!

    Just one quick question: When selecting capacity on the table how can i trim the bytes? so i only get the size capacity in GB.

    Thanks!

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s