SCOM Management Agent Version Discovery

SCOM.Management.Agent.Class.AgentVersion.Discovery (Discovery)

Element properties:

TargetSCOM.Management.Agent.Class
EnabledTrue
Frequency86493
RemotableFalse

Object Discovery Details:

Discovered Classes and their attribuets:

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource Microsoft.Windows.TimedScript.DiscoveryProvider Default

Source Code:

<Discovery ID="SCOM.Management.Agent.Class.AgentVersion.Discovery" Enabled="true" Target="SCOM.Management.Agent.Class" ConfirmDelivery="false" Remotable="true" Priority="Normal">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="SCOM.Management.Agent.Class">
<Property PropertyID="AgentVersion"/>
<Property PropertyID="UpdateRollup"/>
</DiscoveryClass>
</DiscoveryTypes>
<DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedScript.DiscoveryProvider">
<IntervalSeconds>86493</IntervalSeconds>
<SyncTime/>
<ScriptName>SCOM.Management.Agent.Class.AgentVersion.Discovery.vbs</ScriptName>
<Arguments>$MPElement$ $Target/Id$ $Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$</Arguments>
<ScriptBody><Script>' Script to discover agent version and Agent UR level

'Option Explicit

Dim StartTime,EndTime,sTime
'Capture script start time
StartTime = Now

Dim oAPI, oDiscoveryData, oInst, SourceID, ManagedEntityId, TargetComputer, urVersion, objShell, objFSO, fileVer, sngVersion, ScriptName

Dim oArgs
Set oArgs = WScript.Arguments
if oArgs.Count &lt; 3 Then
Wscript.Quit -1
End If

SourceId = oArgs(0)
ManagedEntityId = oArgs(1)
TargetComputer = oArgs(2)

'Load MOMScript API and PropertyBag function
Set oAPI = CreateObject("MOM.ScriptAPI")
Set oDiscoveryData = oAPI.CreateDiscoveryData(0, SourceId, ManagedEntityId)

ScriptName = "SCOM.Management.Agent.Class.AgentVersion.Discovery.vbs"

'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 &amp; "Tools\TMF\" &amp; "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 (" &amp; fileVer &amp; "). UR Level is (" &amp; urVersion &amp; "). Script runtime in seconds: (" &amp; sTime &amp; ")")

Call oAPI.Return(oDiscoveryData)
</Script></ScriptBody>
<TimeoutSeconds>120</TimeoutSeconds>
</DataSource>
</Discovery>