'Load MOMScript API and PropertyBag function
Set oAPI = CreateObject("MOM.ScriptAPI")
Set oDiscoveryData = oAPI.CreateDiscoveryData(0, SourceId, ManagedEntityId)
'Log script event that we are starting discovery
Call oAPI.LogScriptEvent(ScriptName, 1005, 0, "Starting discovery script")
'Get the installation directory for SCOM agent
Set objShell = WScript.CreateObject("WScript.Shell")
sngVersion = objShell.RegRead("HKLM\SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Setup\InstallDirectory")
'Get the version of the SCOM agent file included with every agent and Update Rollup
Set objFSO = CreateObject("Scripting.FileSystemObject")
fileVer = objFSO.GetFileVersion(sngVersion & "Tools\TMF\" & "OMAgentTraceTMFVer.Dll")
'Set a readable UR value for each known UR version
select case fileVer
case "7.1.10184.0"
urVersion = "2012 R2 RTM"
case "7.1.10195.0"
urVersion = "2012 R2 UR2"
case "7.1.10204.0"
urVersion = "2012 R2 UR3"
case "7.1.10211.0"
urVersion = "2012 R2 UR4"
case "7.1.10213.0"
urVersion = "2012 R2 UR5"
case "7.1.10218.0"
urVersion = "2012 R2 UR6"
case "7.1.10229.0"
urVersion = "2012 R2 UR7"
case "7.1.10241.0"
urVersion = "2012 R2 UR8"
case "7.1.10268.0"
urVersion = "2012 R2 UR9"
case "7.1.10285.0"
urVersion = "2012 R2 UR11"
case "7.1.10292.0"
urVersion = "2012 R2 UR12"
case "7.1.10302.0"
urVersion = "2012 R2 UR13"
case "8.0.10918.0"
urVersion = "2016 RTM"
case "8.0.10931.0"
urVersion = "2016 UR1"
case "8.0.10949.0"
urVersion = "2016 UR2"
case "8.0.10970.0"
urVersion = "2016 UR3"
case "8.0.10977.0"
urVersion = "2016 UR4"
'In the case the file version is not known or newer than this script, simply output file version for URVersion
case Else
urVersion = fileVer
end select
'Create discovery data
set oInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='SCOM.Management.Agent.Class']$")
call oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", TargetComputer)
call oInst.AddProperty("$MPElement[Name='SCOM.Management.Agent.Class']/AgentVersion$", fileVer)
call oInst.AddProperty("$MPElement[Name='SCOM.Management.Agent.Class']/UpdateRollup$", urVersion)
call oDiscoveryData.AddInstance(oInst)
'Capture script runtime for logging
EndTime = Now
sTime = DateDiff("s", StartTime, EndTime)
'Log script event that we are ending discovery
Call oAPI.LogScriptEvent(ScriptName, 1005, 0, "Ending script. Agent Version is (" & fileVer & "). UR Level is (" & urVersion & "). Script runtime in seconds: (" & sTime & ")")