Skip to content

Instantly share code, notes, and snippets.

@JustinGrote
Last active July 18, 2019 18:35
Show Gist options
  • Save JustinGrote/a1c71a0c0f4d30d69dccbedc29329521 to your computer and use it in GitHub Desktop.
Save JustinGrote/a1c71a0c0f4d30d69dccbedc29329521 to your computer and use it in GitHub Desktop.
A Dell OMReport Invoker and Parser for SSV Content. Used to gather storage health.
function Invoke-OMReport ($ArgumentList,[Switch]$Raw) {
#Written to be PSv2 Compatible with older systems, e.g. 2008R2 for use in Powershell Remoting
#OFS is used to preserve the "newlines" in the command output for parsing, otherwise they get converted to spaces by default when casting the string array to a single string
$OFS="`r`n"
[String]$omReportResultSSV = & $env:ProgramFiles\Dell\SysMgt\oma\bin\omreport.exe ($ArgumentList -split ' ') -fmt ssv
Remove-Variable OFS
#Matches repeating content with a semicolon, and then additional lines within a "block", a block being defined as ending with a double newline or the end of the string
$ssvRegex = '(?:[^;\r\n]+(?:;[^;\r\n]+){2,}(?:(?:\r\n)|$)){1,}'
if ($omReportResultSSV -notmatch $ssvRegex) {
if ($LASTEXITCODE -ne 0) {
Write-Error $omReportResultSSV
} else {
Write-Warning $omReportResultSSV
}
return
}
if ($Raw) {
return $omReportResultSSV
} else {
return (ConvertFrom-OMReportSSV $omReportResultSSV)
}
}
function ConvertFrom-OMReportSSV ([String]$omReportResultSSV) {
#Matches repeating content with a semicolon, and then additional lines within a "block", a block being defined as ending with a double newline or the end of the string
[Regex]$ssvRegex = '(?:[^;\r\n]+(?:;[^;\r\n]+){2,}(?:(?:\r\n)|$)){1,}'
$omReportResultMatches = $ssvRegex.Matches($omReportResultSSV)
if (-not $omReportResultMatches.count) {
write-warning "No SSV blocks found in the input"
}
foreach ($reportItem in $omReportResultMatches) {
ConvertFrom-CSV -InputObject $reportItem.value.trim() -Delimiter ';'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment