Tag Archives: MimboloveVBScript

Clean Up Old Hardware Inventory Data

Written by Tao Yang

In SCCM, after removing WMI classes that are no longer required from configuration.mof and sms_def.mof, the inventory data still exists in few places.

If you decide to clean them up, MyITForum.com has a great WIKI page for SCCM hardware inventory which talked about different ways to clean up hardware inventory data.

I have tried the free SiteSweeper tool from SCCMExpert.com which was mentioned in the WIKI page. It’s easy to use and you can remove multiple classes from site database at once:


Other than removing the data from site databases throughout the hierarchy, the WMI class which you defined in the configuration.mof still exists in the client. I didn’t bother to look further to find tools/utilities to delete WMI classes, but simple found a sample vbscript from MSDN to modify WMI classes, and modified a little bit:


wbemCimtypeString = 8             ' String datatype
Set objSWbemService = GetObject("Winmgmts:root\cimv2")
Set objClass = objSWbemService.Get()
objClass.Path_.Class = "<name of WMI class you wish to delete>"

' Remove the new class and instance from the repository
If Err &lt;&gt; 0 Then
WScript.Echo Err.Number &amp; "    " &amp; Err.Description
WScript.Echo "Delete succeeded"
End If

' Release SwbemServices object
Set objSWbemService = Nothing

To modify it, specify the WMI class you wish to delete on line 4. If the WMI class is not located in root\CIMV2 namespace, change line 2 as well.

I created a package in SCCM and advertised it to all systems.

Note: When you create the program, make sure you use the syntax “Cscript DeleteWMIClass.vbs” so the output is redirected to command prompt rather than a message box.

Setting SMS_INSTALL_DIR_PATH Environment variable on SCCM site servers for SCOM SCCM management pack

Written by Tao Yang

According to the “Configuration Manager 2007 SP2 Management Pack User’s Guide for Operations Manager 2007 R2 and Operations Manager 2007 SP1” (for MP version 6.0.6000.2), An environment variable named “SMS_INSTALL_DIR_PATH” needs to be created on all SCCM site servers.

I had to do this on 80+ site servers, so I thought why not do this using a script and let SCCM to push it out to all site servers?

Therefore, I wrote a VBScript Set-EnvirVar-For-SCOM.vbs (I didn’t use PowerShell this time because it is easier to push out VBScripts via SCCM).

Source Code:

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colServices = objWMIService.ExecQuery _
("Select * from Win32_service Where Name = 'SMS_SITE_COMPONENT_MANAGER'")

For each item in colServices
ServicePath = item.PathName

IF Left(ServicePath,1) = Chr(34) THEN
ServicePath = Right(ServicePath, Len(ServicePath)-1)
IF Right(ServicePath,1) = Chr(34) THEN
ServicePath = Left(ServicePath, Len(ServicePath)-1)

InstDir = Replace(ServicePath,"\bin\i386\sitecomp.exe","")

IF LEN(InstDir)>0 THEN
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set objVariable = objWMIService.Get("Win32_Environment").SpawnInstance_
objVariable.Name = EnvVarName
objVariable.UserName = "<System>"
objVariable.VariableValue = InstDir
'Wscript.Echo "This is not a SCCM Site Server"

'Wscript.Echo "Done"

This script retrieves the path of the executable (sitecomp.exe) for the SMS_SITE_COMPONENT_MANAGER service via WMI class Win32_Service, and determine the SMS Install Path based on the path to the executable. It then create a new system environment variable if the path is valid. – This means you can run this script against non-SCCM Site servers and it will not create the environment variable on these machines.

Once I’ve tested the script by manually running in on different servers, I then create a SCCM collection called “SCCM Site Servers”. This collection is a query based collection that looks for machines running “SMS_SITE_COMPONENT_MANAGER” service.

Finally, I created a package and deployed it out to this collection.