PowerShell StorCLI

  • Welcome to ITBible, we're your #1 resource for enterprise or homelab IT problems (or just a place to show off your stuff).

Battery Status​

This will return an error if something is wrong otherwise it will return "Healthy."
PowerShell:
param(
    [string]$StorCLILocation = 'C:\Program Files (x86)\MegaRAID Storage Manager\StorCLI.exe', # Path to StorCLI
    [string]$StorCliCommand = "/c0 /bbu show status j"
)

try {
    $ExecuteStoreCLI = & $StorCLILocation $StorCliCommand | out-string
    $ArrayStorCLI = ConvertFrom-Json $ExecuteStoreCLI
} catch {
    $ScriptError = "StorCLI Command has Failed: $($_.Exception.Message)"
    exit
}

foreach($BatteryUnit in $ArrayStorCLI.Controllers.'Command Status'.'Detailed Status'){
    if($BatteryUnit.Status -eq "Failed") {
        $RAIDStatus += "BBU $($BatteryUnit.Ctrl) is failed with message $($BatteryUnit.ErrMsg)`n"
    }
}
#If the variables are not set, We’re setting them to a "Healthy" state as our final action.
if (!$RAIDStatus) { $RAIDStatus = "Healthy" }
if (!$ScriptError) { $ScriptError = "Healthy" }

if ($ScriptError -eq "Healthy")
{
    Write-Host $RAIDStatus
}
else
{
    Write-Host "Error: ".$ScriptError
}
$RAIDStatus = $null
$ScriptError = $null

Version​

This will return the RAID version (this checks the version of StorCLI).
PowerShell:
$cmd = (&"C:\Program Files (x86)\MegaRAID Storage Manager\StorCLI.exe" -v).Trim()
$cmd = ($cmd -split "`n").Trim()
$cmd1 = ($cmd -split "Ver").Trim()
Write-Host $cmd1[2]

Physical Drive Status​

This will return an error if there is an issue with any physical drives and will return "Healthy" otherwise.
PowerShell:
param(
    [string]$StorCLILocation = 'C:\Program Files (x86)\MegaRAID Storage Manager\StorCLI.exe',
    [string]$StorCliCommand = "/c0 /sAll show j"
)

try {
    $ExecuteStoreCLI = & $StorCliLocation $StorCliCommand | out-string
    $ArrayStorCLI= ConvertFrom-Json $ExecuteStoreCLI
}catch{
    $ScriptError = "StorCli Command has Failed: $($_.Exception.Message)"
    exit
}

foreach($PhysicalDrive in $ArrayStorCLI.Controllers.'Response Data'.'Drive Information'){
    if(($($PhysicalDrive.State) -ne "Onln") -and ($($PhysicalDrive.State -ne "GHS"))) {
        $RAIDStatus += "Physical Drive $($PhysicalDrive.'DID') With Size $($PhysicalDrive.'Size') is $($PhysicalDrive.State)`n"
    }
}
#If the variables are not set, We’re setting them to a “Healthy” state as our final action.
if (!$RAIDStatus) { $RAIDStatus = "Healthy" }
if (!$ScriptError) { $ScriptError = "Healthy" }

if ($ScriptError -eq "Healthy")
{
    Write-Host $RAIDStatus
}
else
{
    Write-Host "Error: ".$ScriptError
}
$RAIDStatus = $null
$ScriptError = $null

Virtual Drive Status​

This will return an error if there is an issue with any virtual drives and will return "Healthy" otherwise.
PowerShell:
param(
    [string]$StorCLILocation = 'C:\Program Files (x86)\MegaRAID Storage Manager\StorCLI.exe',
    [string]$StorCliCommand = "/c0 /vAll show j"
)

try {
    $ExecuteStoreCLI = & $StorCliLocation $StorCliCommand | out-string
    $ArrayStorCLI= ConvertFrom-Json $ExecuteStoreCLI
}catch{
    $ScriptError = "StorCli Command has Failed: $($_.Exception.Message)"
    exit
}

foreach($VirtualDrive in $ArrayStorCLI.Controllers.'Response Data'.'Virtual Drives'){
    if(($($VirtualDrive.State) -ne "Optl")) {
        $RAIDStatus += "Virtual Drive $($VirtualDrive.'DG/VD') With Size $($VirtualDrive.'Size') is $($VirtualDrive.State)`n"
    }
}
#If the variables are not set, We’re setting them to a “Healthy” state as our final action.
if (!$RAIDStatus) { $RAIDStatus = "Healthy" }
if (!$ScriptError) { $ScriptError = "Healthy" }

if ($ScriptError -eq "Healthy")
{
    Write-Host $RAIDStatus
}
else
{
    Write-Host "Error: ".$ScriptError
}
$RAIDStatus = $null
$ScriptError = $null