Created
July 27, 2014 13:58
-
-
Save Nora-Ballard/dc877248b2d8d99cbd44 to your computer and use it in GitHub Desktop.
Reads HP Blade Enclosure XML (/xmldata?item=all) inventory page and formats in a PS friendly object. Does not require authentication to the chassis, so good for inventory in a new environment or quick status check.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-HPEnclosure { | |
param( | |
[Parameter(Mandatory,ValueFromPipeline)] | |
[string]$ComputerName | |
) | |
$URL = 'http://{0}/xmldata?item=All' -f $ComputerName | |
$Result = [xml](Invoke-RestMethod -Uri $URL -Method Get) | |
$Enclosure = [pscustomobject]@{ | |
'Name' = $Result.RIMP.INFRA2.ENCL | |
'SerialNumber' = $Result.RIMP.INFRA2.ENCL_SN | |
'Rack' = $Result.RIMP.INFRA2.RACK | |
'ProductName' = $Result.RIMP.INFRA2.PN | |
'Diagnostics' = [pscustomobject]@{} | |
'FanStatus' = $Result.RIMP.INFRA2.FANS.STATUS | |
'FansRedundant' = if ($Result.RIMP.INFRA2.FANS.REDUNDANCY -eq 'REDUNDANT') {$true} else {$false} | |
'Power' = $Result.RIMP.INFRA2.POWER.TYPE | |
'PowerStatus' = $Result.RIMP.INFRA2.POWER.STATUS | |
'PowerRedundant' = if ($Result.RIMP.INFRA2.POWER.REDUNDANCY -eq 'REDUNDANT') {$true} else {$false} | |
'PowerSupplyNeed'= $Result.RIMP.INFRA2.POWER.NEEDED_PS | |
'PowerSupplyWant'= $Result.RIMP.INFRA2.POWER.WANTED_PS | |
'PowerOnFlag' = switch ($Result.RIMP.INFRA2.POWER.POWERONFLAG) { 'true' {$true}; 'false' {$false}} | |
'PowerSupplies' = @() | |
'Blades' = @() | |
'Switches' = @() | |
'OAs' = @() | |
} | |
Add-Member -InputObject $Enclosure -MemberType ScriptProperty -Name ArePowerSuppliesOK -Value { | |
@($this.PowerSupplies | Where { ($_.Status -ne 'OK')}).Count -eq 0 | |
} | |
Add-Member -InputObject $Enclosure -MemberType ScriptProperty -Name AreBladesOK -Value { | |
@($this.Blades | Where { ($_.Status -ne 'OK') -and ($_.PowerState -ne 'OFF')}).Count -eq 0 | |
} | |
Add-Member -InputObject $Enclosure -MemberType ScriptProperty -Name AreSwitchesOK -Value { | |
@($this.Switches | Where { ($_.Status -ne 'OK')}).Count -eq 0 | |
} | |
Add-Member -InputObject $Enclosure -MemberType ScriptProperty -Name AreOAsOK -Value { | |
@($this.OAs | Where { ($_.Status -ne 'OK')}).Count -eq 0 | |
} | |
$Result.RIMP.INFRA2.DIAG.ChildNodes | ForEach-Object { | |
if (($_.'#Text' -notin @('NOT_TESTED','NOT_RELEVANT')) -and ($_.Name -ne '#whitespace')) { | |
$MemberProperties = @{ | |
'InputObject' = $Enclosure.Diagnostics | |
'MemberType' = 'NoteProperty' | |
'Name' = $_.Name.ToString() | |
'Value' = $_.'#Text'.ToString() | |
} | |
Add-Member @MemberProperties | |
} | |
} | |
$Enclosure.Blades += $Result.RIMP.INFRA2.BLADES.BLADE | ForEach-Object { | |
$Node = [pscustomobject]@{ | |
'Bay' = $_.BAY.CONNECTION | |
'Type' = $_.TYPE | |
'Manufacturer' = $_.MANUFACTURER | |
'ProductName' = $_.SPN | |
'SerialNumber' = $_.BSN | |
'Status' = $_.STATUS | |
'UIDStatus' = $_.UIDSTATUS | |
'PowerState' = $_.POWER.POWERSTATE | |
'Diagnostics' = [pscustomobject]@{ | |
'PowerConsumed'= $_.POWER.POWER_CONSUMED | |
} | |
'iLOIPAddress' = $_.MGMTIPADDR | |
'iLODNSName' = $_.MGMTDNSNAME | |
'Mezzanine' = @( | |
$_.PORTMAP.MEZZ.DEVICE | ForEach-Object { | |
if ($_ -ne $null) { | |
[pscustomobject]@{ | |
'Name' = $_.NAME | |
'Type' = $_.TYPE | |
'Status' = $_.STATUS | |
'Ports' = $_.PORT | |
} | |
} | |
} | |
) | |
} | |
$_.DIAG.ChildNodes | ForEach-Object { | |
if (($_.'#Text' -notin @('NOT_TESTED','NOT_RELEVANT')) -and ($_.Name -ne '#whitespace')) { | |
$MemberProperties = @{ | |
'InputObject' = $Node.Diagnostics | |
'MemberType' = 'NoteProperty' | |
'Name' = $_.Name.ToString() | |
'Value' = $_.'#Text'.ToString() | |
} | |
Add-Member @MemberProperties | |
} | |
} | |
$Node | |
} | |
$Enclosure.Switches += $Result.RIMP.INFRA2.SWITCHES.SWITCH | ForEach-Object { | |
$Node = [pscustomobject]@{ | |
'Bay' = $_.BAY.CONNECTION | |
'Manufacturer' = $_.MANUFACTURER | |
'ProductName' = $_.SPN | |
'SerialNumber' = $_.BSN | |
'Status' = $_.STATUS | |
'UIDStatus' = $_.UIDSTATUS | |
'PowerState' = $_.POWER.POWERSTATE | |
'Diagnostics' = [pscustomobject]@{} | |
'ManagementIP' = $_.MGMTIPADDR | |
'ManagementURL'= $_.MGMTURL | |
} | |
$_.DIAG.ChildNodes | ForEach-Object { | |
if (($_.'#Text' -notin @('NOT_TESTED','NOT_RELEVANT')) -and ($_.Name -ne '#whitespace')) { | |
$MemberProperties = @{ | |
'InputObject' = $Node.Diagnostics | |
'MemberType' = 'NoteProperty' | |
'Name' = $_.Name.ToString() | |
'Value' = $_.'#Text'.ToString() | |
} | |
Add-Member @MemberProperties | |
} | |
} | |
$Node | |
} | |
$Enclosure.OAs += $Result.RIMP.INFRA2.MANAGERS.MANAGER | ForEach-Object { | |
$Node = [pscustomobject]@{ | |
'Bay' = $_.BAY.CONNECTION | |
'Manufacturer' = $_.MANUFACTURER | |
'Name' = $_.NAME | |
'Role' = $_.ROLE | |
'FirmwareVersion'= $_.FWRI | |
'WizardStatus' = $_.WIZARDSTATUS | |
'Status' = $_.STATUS | |
'UIDStatus' = $_.UIDSTATUS | |
'PowerState' = $_.POWER.POWERSTATE | |
'Diagnostics' = [pscustomobject]@{} | |
'ManagementIP' = $_.MGMTIPADDR | |
} | |
$_.DIAG.ChildNodes | ForEach-Object { | |
if (($_.'#Text' -notin @('NOT_TESTED','NOT_RELEVANT')) -and ($_.Name -ne '#whitespace')) { | |
$MemberProperties = @{ | |
'InputObject' = $Node.Diagnostics | |
'MemberType' = 'NoteProperty' | |
'Name' = $_.Name.ToString() | |
'Value' = $_.'#Text'.ToString() | |
} | |
Add-Member @MemberProperties | |
} | |
} | |
$Node | |
} | |
$Enclosure.PowerSupplies += $Result.RIMP.INFRA2.POWER.POWERSUPPLY | ForEach-Object { | |
$Node = [pscustomobject]@{ | |
'Bay' = $_.BAY.CONNECTION | |
'PartNumber' = $_.PN | |
'SerialNumber' = $_.SN | |
'Capacity' = $_.CAPACITY | |
'ActualOutput' = $_.ACTUALOUTPUT | |
'ACinput' = $_.ACINPUT | |
'Status' = $_.STATUS | |
'FirmwareVersion'= $_.FWRI | |
'Diagnostics' = [pscustomobject]@{} | |
} | |
$_.DIAG.ChildNodes | ForEach-Object { | |
if (($_.'#Text' -notin @('NOT_TESTED','NOT_RELEVANT')) -and ($_.Name -ne '#whitespace')) { | |
$MemberProperties = @{ | |
'InputObject' = $Node.Diagnostics | |
'MemberType' = 'NoteProperty' | |
'Name' = $_.Name.ToString() | |
'Value' = $_.'#Text'.ToString() | |
} | |
Add-Member @MemberProperties | |
} | |
} | |
$Node | |
} | |
$Enclosure | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment