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).
Set objWMIService = GetObject("winmgmts:" _
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","")
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
‘Wscript.Echo "This is not a SCCM Site Server"
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.