Scripted Extensions

Some details are difficult or impossible to collect using MIF or MOF hardware inventory extensions. In those cases, consider writing a script to collect the details using any of the many techniques available to script, and then add the details to the SMS hardware inventory.

Scripts can write static or dynamic MIF or MOF files. Scripts that write MIF files use exactly the same techniques as any script that writes text files. Those techniques are well documented in many sources, so this chapter does not describe how to write scripts that write MIF files.

If a script writes to a MOF file, the MOF file then has to be compiled, so it is more efficient to write the MOF data directly to WMI. The rest of this section describes how to write scripts that write to WMI. The WMI principles are the same as those described in the "Common MOF Extensions" section later in this chapter.

Scripts that write hardware inventory extension data to WMI must do three things:

  1. Create the data class, if it does not exist already.

  2. Collect the data.

  3. Write the data to WMI.

In addition, SMS_def.mof must be extended to include a reporting class for the collected data. For example, add the following MOF to SMS_def.mof:

#pragma namespace("\\\\.\\ROOT\\CIMV2\\sms")
[SMS_ReporT(TRUE),
SMS_Group_Name("Asset Wizard Results"),
SMS_Class_ID("MICROSOFT|ASSETWIZARD|1.0")]
class SMS_AssetWizard_1 : SMS_Class_Template
{
    [SMS_Report(TRUE),key] uint32 Type;
    [SMS_Report(TRUE)] string ContactFullName;
    [SMS_Report(TRUE)] string ContactEmail;
    [SMS_Report(TRUE)] string ContactPhone;
    [SMS_Report(TRUE)] string ContactLocation;
    [SMS_Report(TRUE)] string SysLocationSite;
    [SMS_Report(TRUE)] string SysLocationBuilding;
    [SMS_Report(TRUE)] string SysLocationRoom;
    [SMS_Report(TRUE)] string SysUnitManufacturer;
    [SMS_Report(TRUE)] string SysUnitModel;
    [SMS_Report(TRUE)] string SysUnitAssetNumber;
    [SMS_Report(TRUE)] boolean SysUnitIsLaptop;
};

The Microsoft Systems Management Server 2003 Software Development Kit includes a Visual Basic program, Asset Wizard, which prompts the user for various details, such as the user's office number and telephone number. It then adds the details to the SMS hardware inventory. The next example adds the same details to the SMS hardware inventory, but from a script. The example illustrates all the steps to write to WMI except for collecting the data. In this example, the data is in the script itself. You can use any technique to collect the data that is supported by scripting.

Set loc = CreateObject("WbemScripting.SWbemLocator")
Set WbemServices = loc.ConnectServer(, "root\CIMv2")
    On Error Resume Next
    Set WbemObject = WbemServices.Get("SMS_AssetWizard_1")
'If this call failed, we need to make the SMS_AssetWizard_1 data class
If Err Then
   'Retrieve blank class
   Set WbemObject = WbemServices.Get
   'Set class name
   WbemObject.Path_.Class = "SMS_AssetWizard_1"   'Add Properties (8 = CIM_STRING, 11 = CIM_BOOLEAN)
   WbemObject.Properties_.Add "Type", 19
   WbemObject.Properties_.Add "ContactFullName", 8
   WbemObject.Properties_.Add "ContactEmail", 8
   WbemObject.Properties_.Add "ContactPhone", 8
   WbemObject.Properties_.Add "ContactLocation", 8
   WbemObject.Properties_.Add "SysLocationSite", 8
   WbemObject.Properties_.Add "SysLocationBuilding", 8
   WbemObject.Properties_.Add "SysLocationRoom", 8
   WbemObject.Properties_.Add "SysUnitManufacturer", 8
   WbemObject.Properties_.Add "SysUnitModel", 8
   WbemObject.Properties_.Add "SysUnitAssetNumber", 8
   WbemObject.Properties_.Add "SysUnitIsLaptop", 11
   'Add key qualifier to Type property
   WbemObject.Properties_("Type").Qualifiers_.Add "key", True
   WbemObject.Put_
End if
On Error Goto 0
Set WbemServices = loc.ConnectServer(, "root\CIMv2")
Set WbemObject = WbemServices.Get("SMS_AssetWizard_1").SpawnInstance_
' Store property values (the data!)
WbemObject.Type = 0
WbemObject.ContactFullName = "John Smith"
WbemObject.ContactEmail = "JSmith"
WbemObject.ContactPhone = "(425) 707-9791"
WbemObject.ContactLocation = "Redmond"
WbemObject.SysLocationSite = "Campus"
WbemObject.SysLocationBuilding = "24"
WbemObject.SysLocationRoom = "1168"
WbemObject.SysUnitManufacturer = "Dell"
WbemObject.SysUnitModel = "GX1"
WbemObject.SysUnitAssetNumber = "357701"
WbemObject.SysUnitIsLaptop = False
'WMI will overwrite the existing instance
WbemObject.Put_
For More Information

Did you find this information useful? Please send your suggestions and comments about the documentation to smsdocs@microsoft.com.