Serial numbers & models with win32_SystemEnclosure & SMBios

Discussion in 'Scripting' started by James Murdoch, Jan 21, 2004.

  1. I am trying to get the serial number and model for a set
    of servers and I can get the serial numbers, on most, but
    not the models. How can I get the models and why do some
    servers not show the serial numbers? What other
    properties can I list out?


    Set objWMIService = GetObject("winmgmts:\\" & TargetServer
    & "\root\cimv2")
    Set colSMBIOS = objWMIService.ExecQuery ("Select * from
    Win32_SystemEnclosure")
    For Each objSMBIOS in colSMBIOS
    strSerial = Trim(objSMBIOS.SerialNumber)
    If len(strSerial) > 1 Then
    Wscript.Echo "Serial Number," & strSerial
    End If
    Next

    Wscript.Quit
     
    James Murdoch, Jan 21, 2004
    #1
    1. Advertisements

  2. I found this to be a bit of a pain, because the information is spread
    all over the SMBIOS data. (This is the fault of the system vendor,
    not Microsoft.)

    The code I eventually settled on was this (in Perl):

    my ($vendor, $serial) = ('?', '?');
    # Get BIOS objects from WMI. See
    # <http://msdn.microsoft.com/library/en-us/wmisdk/wmi/win32_bios.asp>
    my @bioses = Win32::OLE::Enum->All
    ($wmi->InstancesOf ('Win32_BIOS'));
    my $bios = $bioses[0];
    my @enclosures = Win32::OLE::Enum->All
    ($wmi->InstancesOf ('Win32_SystemEnclosure'));
    my $enclosure = $enclosures[0];

    my $new_vendor = $bios->{'Manufacturer'};
    defined $new_vendor
    and $vendor = $new_vendor;
    my $new_serial = $bios->{'SerialNumber'};
    if (defined $new_serial && $new_serial =~ /\S/) {
    $serial = $new_serial;
    }
    else {
    $new_vendor = $enclosure->{'Manufacturer'};
    defined $new_vendor
    and $vendor = $new_vendor;
    foreach my $key ('SerialNumber', 'SMBIOSAssetTag') {
    $new_serial = $enclosure->{$key};
    defined $new_serial && $new_serial =~ /\S/
    and $serial = $new_serial;
    }
    }
    return ($vendor, $serial);

    In English: Default to using the Manufacturer and SerialNumber
    properties of Win32_BIOS. Fall back to using the Manufacturer,
    SerialNumber, and SMBIOSAssetTag of Win32_SystemEnclosure.

    This works well enough on the variety of machines I have at hand,
    including Dell workstations/laptop/servers and IBM Thinkpads.

    - Pat
    http://unattended.sourceforge.net/
     
    Patrick J. LoPresti, Jan 21, 2004
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.