Setup: A HP server with Windows OS and WMI enabled. Latest WBEM drivers installed.
Problem: You want to query server details regarding the Storage Array Controller and disks installed.
Solution: Run this PowerShell script from a remote computer.
# The script takes the name of the remote computer as parameter
param(
[string] $strComputer
)
# ask for credentials to connect to remote computer. Credentials can be stored on the disk for unattended execution.
$cred = get-credential
$cd = "" | select Name
Add-Member -memberType NoteProperty -name RaidController -inputObject $cd -value "N/A"
Add-Member -memberType NoteProperty -name HDD_Raid_Configuration -inputObject $cd -value "N/A"
Add-Member -memberType NoteProperty -name HDD_Configuration -inputObject $cd -value "N/A"
Add-Member -memberType NoteProperty -name No_HDD_Bays_Used -inputObject $cd -value 0
Add-Member -memberType NoteProperty -name No_HDD_Bays -inputObject $cd -value 0
$cd.name = $strComputer
# Disk array subsystem
$StorageVolume = Get-WmiObject -class HPSA_StorageVolume -computername $strComputer -namespace "root\HPQ" -ErrorAction SilentlyContinue -credential $cred
$ArrayController = Get-WmiObject -class HPSA_ArrayController -computername $strComputer -namespace "root\HPQ" -ErrorAction SilentlyContinue -credential $cred| select ElementName
$cd.RaidController = $ArrayController.ElementName
$DiskDrive = Get-WmiObject -class HPSA_DiskDrive -computername $strComputer -namespace "root\HPQ" -ErrorAction SilentlyContinue -credential $cred
$StorageVolume = Get-WmiObject -class HPSA_StorageVolume -computername $strComputer -namespace "root\HPQ" -ErrorAction SilentlyContinue -credential $cred| select elementname,deviceid
$RaidDisks = @()
Get-WmiObject -class HPSA_StorageExtentStorageVolume -computername $strComputer -namespace "root\HPQ" -ErrorAction SilentlyContinue -credential $cred| %{$rd = ""| select raid,disk;$rd.disk=$_.antecedent.split(",")[1].split("=")[1].trimstart('"').trimend('"');$rd.raid=$_.dependent.split(",")[1].split("=")[1].trimstart('"').trimend('"');$RaidDisks += $rd}
$alldisks=@{}
Get-WmiObject -class HPSA_DiskPhysicalPackage -computername $strComputer -namespace "root\HPQ" -ErrorAction SilentlyContinue -credential $cred| select name,model,serialnumber,tag | %{$dsk = "" | select bay,model,sn,tag;$dsk.bay=$_.name.split()[2];$dsk.model=$_.model;$dsk.sn = $_.serialnumber;$dsk.tag = $_.tag;$alldisks[$_.tag] += $dsk}
$strAllDisks = ""
$alldisks.Getenumerator() | sort value[1] | %{$strAllDisks+="("+$_.value.bay+";"+$_.value.model+";"+($_.value.sn -replace "\s *", " ").trim() +")"}
$RaidDisks | %{Add-Member -inputobject $_ -MemberType noteproperty -Name bay -Value $alldisks[$_.disk].bay}
$RaidDisks | %{$di=$_.raid;$fn=($StorageVolume | where {$_.deviceid -eq $di}).elementname;Add-Member -inputobject $_ -MemberType noteproperty -Name FullName -Value $fn}
$Raid_configuration = ""
foreach ($lv in ($RaidDisks | sort raid -Unique)) {
$dd = $lv.FullName+"("
($RaidDisks | where {$_.raid -eq $lv.raid} | select raid,bay| sort bay) | %{$dd+=$_.bay+","}
$dd = $dd.trimend(",")
$dd += ")"
$Raid_configuration +=$dd+"; "
}
$cd.HDD_Raid_Configuration = $Raid_configuration.trimend("; ")
$hdd_bays=0
Get-WmiObject -class HPSA_DriveCage -computername $strComputer -namespace "root\HPQ" -ErrorAction SilentlyContinue -credential $cred| select drivebays | %{$hdd_bays+=$_.drivebays}
$cd.HDD_Configuration = $strAllDisks
$cd.No_HDD_Bays_Used = $alldisks.count
$cd.No_HDD_Bays = $hdd_bays
$cd
Hi there,
I have tried your script but unfortunately it did not work – I got no data back from the ‘Get-WmiObject -class HPSA_StorageVolume -computername $strComputer -namespace “root\HPQ” ‘ query.
Do you know of any other way of accessing the date from an array controller through wmi query and powershell. I would be very interested in working with you on a solution as I have a practical use for the script.
Thanks
Peter Server Fixes
Hi Peter,
Do you have the HP WBEM provider installed ? You can use WMI Explorer (http://wmie.codeplex.com) to verify if namespace exists and has all the classes.
Also, you can try locally on the server first by removing -computername parameter.
Mihai.
Hi,
Thank you for this script, one thing I corrected though was the line “$result.name = $strComputer” which I changed to “$cd.name = $strComputer”.
Regards
Anthony
Thanks for spotting that issue. Corrected.
Mihai