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

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
Next

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

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

EnvVarName = "SMS_INSTALL_DIR_PATH"
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
objVariable.Put_
ELSE
'Wscript.Echo "This is not a SCCM Site Server"
END IF

'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.

2 comments

  1. I did make one change:

    objVariable.Put_
    Wscript.Echo “This is an SCCM Site Server-Path has been set”
    ELSE
    Wscript.Echo “This is not a SCCM Site Server”
    END IF
    Wscript.Echo “Have a Nice Day!”

Leave a Reply

%d bloggers like this: