I searched quite a bit looking for a way to get an FC card’s WWN from WMI. I found some information indicating it might be in the root\WMI namespace so I used Scriptomatic 2.0 to look through the classes in that namespace until I finally found it. It was in QL_FibrePortNPIVAttributes (I assume this classis added by the QLogic driver installation…yeah the QL gave it away…).
Unfortunately the numbers of the WWN are returned in decimal rather than in hex, the digit groups are returned separated by commas, and single digits are used when the number is below 10. So it looks like this:
WWPN: 80,6,11,0,0,194,154,2
Well, we can’t have that! So I wrote a script to grab the information and convert it hex, group digits with a colon and “pad” an extra zero if the decimal value was under 10. Here is the script:
On Error Resume Next
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
arrComputers = Array(".")
For Each strComputer In arrComputers
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\WMI")
Set colItems = objWMIService.ExecQuery("SELECT * FROM QL_FibrePortNPIVAttributes", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
var1 = objItem.WWPN
For i = 0 To UBound(var1)
If len(Hex(var1(i))) < 2 then
var2 = "0" + Hex(var1(i))
Else
var2 = Hex(var1(i))
End If
tmpVar1 = tmpVar1 & ":" & var2
tmpVar2 = mid(tmpVar1, 2)
Next
wscript.echo tmpVar2
tmpVar1 = ""
tmpVar2 = ""
Next
Next
This returns a beautifully formatted (yes I am a geek) WWN…observe:
50:06:0B:00:00:C2:9A:00

It turns out there is a better WMI class to use, and the code I wrote “reinvents a wheel” that Microsoft already supplied. The WMI class is called MSFC_FCAdapterHBAAttributes and is under the root\wmi namespace on Win2008. It will also show up on earlier OS versions if you install FCInfo. Most of this is covered in my next blog post.