Query Windows Systems from the CLI without relying on OEM tool-chains.
I recently posted about using systool and the /sys/class special filesystem to get FC HBA information. That’s great if you use Linux, but less helpful if you run Windows. This post will take you through the ways of getting the same information from your HBA, but on a recent versions of Windows system (where recent is defined as having WMI classes, and possibly PowerShell installed). It has to be said that I learned a lot of this from Ben Wilkinson’s post on Technet’s Scriptcenter.
First, some background. It doesn’t appear that Windows makes the HBA information available unless you’ve run the fcinfo tool, so if you can’t run this (once is enough), on every system – perhaps at install time, via your automated build system (you have one of these, right?
, then you’re stuck installing the proprietary toolchain (although, if you can do that, you should probably install fcinfo at the same time..).
Once you’ve done that, then Windows has two Windows Windows Management Instrumentation (hereafter WMI) classes defined and query-able via any WMI tool (in this case we’re going to use PowerShell because its got WMI baked in, but you can get to this with Perl and many other languages and methods). WMI is definitely the way to get information out of Windows systems, the more so as they move to CMI and SMI-S, WBEM etc with Windows 8/Server 2012 etc (but that’s another whole series of blog posts and covered better by others);
We’re going to concentrate on the former here since the latter has just the WWPN’s of interest (IMHO, anyway – take a look yourself to decide – I’m not the boss of you!).
The reason I’m using PowerShell here is it really is the dogs dangly bits when it comes to working with Windows objects. Take this one-liner, run from a powershell console;
Get-WmiObject -class MSFC_FCAdapterHBAAttributes -computername MyTestServer -namespace "root\WMI" | Get-Member
This produces;
TypeName: System.Management.ManagementObject#root\WMI\MSFC_FCAdapterHBAAttributes
Name MemberType Definition
---- ---------- ----------
Active Property System.Boolean Active {get;set;}
DriverName Property System.String DriverName {get;set;}
DriverVersion Property System.String DriverVersion {get;set;}
FirmwareVersion Property System.String FirmwareVersion {get;set;}
HardwareVersion Property System.String HardwareVersion {get;set;}
HBAStatus Property System.UInt32 HBAStatus {get;set;}
InstanceName Property System.String InstanceName {get;set;}
Manufacturer Property System.String Manufacturer {get;set;}
MfgDomain Property System.String MfgDomain {get;set;}
Model Property System.String Model {get;set;}
ModelDescription Property System.String ModelDescription {get;set;}
NodeSymbolicName Property System.String NodeSymbolicName {get;set;}
NodeWWN Property System.Byte[] NodeWWN {get;set;}
NumberOfPorts Property System.UInt32 NumberOfPorts {get;set;}
OptionROMVersion Property System.String OptionROMVersion {get;set;}
SerialNumber Property System.String SerialNumber {get;set;}
UniqueAdapterId Property System.UInt64 UniqueAdapterId {get;set;}
VendorSpecificID Property System.UInt32 VendorSpecificID {get;set;}
__CLASS Property System.String __CLASS {get;set;}
__DERIVATION Property System.String[] __DERIVATION {get;set;}
__DYNASTY Property System.String __DYNASTY {get;set;}
__GENUS Property System.Int32 __GENUS {get;set;}
__NAMESPACE Property System.String __NAMESPACE {get;set;}
__PATH Property System.String __PATH {get;set;}
__PROPERTY_COUNT Property System.Int32 __PROPERTY_COUNT {get;set;}
__RELPATH Property System.String __RELPATH {get;set;}
__SERVER Property System.String __SERVER {get;set;}
__SUPERCLASS Property System.String __SUPERCLASS {get;set;}
ConvertFromDateTime ScriptMethod System.Object ConvertFromDateTime();
ConvertToDateTime ScriptMethod System.Object ConvertToDateTime();
Which is using the Get-Member commandlet to query the object produced by Get-WmiObject -class MSFC_FCAdapterHBAAttributes -computername MyTestComputer -namespace "root\WMI" to see what items and methods we can get out of the datastructure of that particular WMI namespace. This is about as deep as I’m going to go into WMI and Powershell, by the way; if you want more there are many, many good books on the subject, sometimes free from Microsoft (or coming bundled with your Technet subscription).
You’re probably thinking, that this is nice and all, but you actually want to know useful information about the computer, like what its WWNN’s are, who manufactured the card, what the firmware is and so forth. Well, if you look through the data structure above, or the link to the documentation for the WMI object, you’ll see that’s indeed what we can get.
Time for another one-liner;
Get-WmiObject -class MSFC_FCAdapterHBAAttributes -computername MyTestServer -namespace "root\WMI" | ForEach-Object { $_ }
This will provide;
__GENUS : 2
__CLASS : MSFC_FCAdapterHBAAttributes
__SUPERCLASS :
__DYNASTY : MSFC_FCAdapterHBAAttributes
__RELPATH : MSFC_FCAdapterHBAAttributes.InstanceName="PCI\\VEN_10DF&DEV_FD00&SUBSYS_FD0010DF&REV_01\\3&172e68dd&0&10_0"
__PROPERTY_COUNT : 18
__DERIVATION : {}
__SERVER : PCMEDSRV2
__NAMESPACE : root\WMI
__PATH : \\PCMEDSRV2\root\WMI:MSFC_FCAdapterHBAAttributes.InstanceName="PCI\\VEN_10DF&DEV_FD00&SUBSYS_FD0010DF&REV_01\\3&172e68dd&0&10_0"
Active : True
DriverName : elxstor
DriverVersion : 5-2.00A12
FirmwareVersion : 2.10A7
HardwareVersion : 1036406D
HBAStatus : 0
InstanceName : PCI\VEN_10DF&DEV_FD00&SUBSYS_FD0010DF&REV_01\3&172e68dd&0&10_0
Manufacturer : Emulex Corporation
MfgDomain : com.emulex
Model : FC2243
ModelDescription : HP FC2243 4Gb PCI-X 2.0 DC HBA
NodeSymbolicName : Emulex FC2243 FV2.10A7 DV5-2.00A12 PCMEDSRV2
NodeWWN : {32, 0, 0, 0…}
NumberOfPorts : 1
OptionROMVersion : 5.01A8
SerialNumber : MY10634B9K
UniqueAdapterId : 4480335924126810144
VendorSpecificID : 4244639967
..and more for each port on each Fiber Channel Host Bus Adapter present on the system
Which is nice, but not very readable. So lets select just the bits we want, and format them slightly nicer;
Get-WmiObject -class MSFC_FCAdapterHBAAttributes -computername MyTestServer -namespace "root\WMI" | Select-Object DriverVersion, FirmwareVersion, Manufacturer, Model, SerialNumber | Format-Table -AutoSize
which gives (on my system);
DriverVersion FirmwareVersion Manufacturer Model SerialNumber
------------- --------------- ------------ ----- ------------
5-2.00A12 2.10A7 Emulex Corporation FC2243 MY10734B9L
5-2.00A12 2.10A7 Emulex Corporation FC2243 MY10734B9L
9.1.7.18 3.03.25 QLogic Corporation QLA2342 L87589
9.1.7.18 3.03.25 QLogic Corporation QLA2342 L87589
Notice that I’m querying a local computer, but, firewall and user permissions permitting, I could query any system I have access to by providing a different name to the -computername parameter.
At this point, you should be in a position to understand the Get-HBA-Info function that Ben Wilkinson provided in the initial link above. Personally, I’ve got this in my .profile, so I can run it from my PowerShell prompt without having to remember the above object selections and WMI classes;
PS U:\> Get-HBA-Info MyTestServer
NodeWWN DriverVersion ModelDescription FirmwareVersion Active ComputerName SerialNumber
------- ------------- ---------------- --------------- ------ ------------ ------------
20:0:0:0:d9:69:3d:3f 5-2.00A12 HP FC2243 4Gb PCI-X 2.0 DC HBA 2.10A7 True MYTESTSERVER MY10734B10K
…and on for every fiber port in every adaptor.
Also be aware that if the computer you query doesn’t have an FC HBA or have fcinfo run at least once, you’re likely to get an error like this;
PS U:\> Get-HBA-Info MyTestNonSANServer
Get-WmiObject : Not supported
At line:9 char:22
+ Get-WmiObject <<<< -class MSFC_FCAdapterHBAAttributes -computername $Computer -namespace $namespace |
+ CategoryInfo : InvalidOperation: (:) [Get-WmiObject], ManagementException
+ FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
See Also
- http://en.wikipedia.org/wiki/Windows_Management_Instrumentation
- http://gallery.technet.microsoft.com/scriptcenter/Find-HBA-and-WWPN-53121140
- “Using the Get-WMiObject Cmdlet”: http://technet.microsoft.com/en-us/library/ee176860.aspx
- MSFC_FCAdapterHBAAttributes structure: http://msdn.microsoft.com/en-gb/library/windows/hardware/ff562495%28v=vs.85%29.aspx
- MSFC_FibrePortHbaAttributes structure: http://msdn.microsoft.com/en-gb/library/windows/hardware/ff562510%28v=vs.85%29.aspx

