Essentials Managed Computer Windows Update Agent Discovery

Microsoft.SystemCenter.Essentials.EssentialsManagedComputerWUAgentDiscovery (Discovery)

Knowledge Base article:

Summary

Discovers Windows Update agent on all Essentials Managed Computers.

Element properties:

TargetMicrosoft.SystemCenter.HealthService
EnabledTrue
Frequency86400
RemotableFalse

Object Discovery Details:

Discovered Classes and their attribuets:
Discovered relationships and their attribuets:

Member Modules:

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

Source Code:

<Discovery ID="Microsoft.SystemCenter.Essentials.EssentialsManagedComputerWUAgentDiscovery" Enabled="onEssentialMonitoring" Target="SC!Microsoft.SystemCenter.HealthService" ConfirmDelivery="false" Remotable="true" Priority="Normal">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="SCEInternal!Microsoft.SystemCenter.Essentials.EssentialsManagedComputer"/>
<DiscoveryClass TypeID="Microsoft.SystemCenter.Essentials.WUAgent"/>
<DiscoveryRelationship TypeID="Microsoft.SystemCenter.Essentials.EssentialsManagedComputerContainsWUAgent"/>
</DiscoveryTypes>
<DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedScript.DiscoveryProvider">
<IntervalSeconds>86400</IntervalSeconds>
<SyncTime/>
<ScriptName>DiscoverWUAgent.vbs</ScriptName>
<Arguments>$MPElement$ $Target/Id$ $Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$</Arguments>
<ScriptBody><Script>
'****************************************************************************
'Copyright (c) Microsoft Corporation. All rights reserved.

' Parameters that should be passed to this script
' 0 MPElement ID ($MPElement$)
' 1 Target Id for ME this rule is running against ($Target/Id$)
' 2 Computer (FQDN)
'*************************************************************************
Option Explicit
SetLocale("en-us")
CONST HKLM = &amp;H80000002

Dim oArgs
Set oArgs = WScript.Arguments
if oArgs.Count &lt;&gt; 3 Then
Quit()
End If

Dim SourceID, ManagedEntityId, TargetComputer

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

Dim oAPI, oDiscoveryData

'Create Mom ScriptAPI object
Set oAPI = MOMCreateObject("MOM.ScriptAPI")

'Create Discovery data object
set oDiscoveryData = oAPI.CreateDiscoveryData(0, SourceId, ManagedEntityId)

If DoDiscovery(TargetComputer, oDiscoveryData) &gt;= 0 Then
Call oAPI.Return(oDiscoveryData)
Else
Quit()
End If

' Does the actual discovery
Function DoDiscovery(ByVal sTargetComputer, ByVal oDisc)
Dim oEssentialsAgentInstance, oWUAgentInstance, oRelCon

On Error Resume Next
' Get Update server for this WU Agent
Dim objReg, strWUServer
Set objReg = GetObject("winmgmts:root\default:StdRegProv")
If objReg Is Nothing then
ThrowScriptErrorNoAbort "Unabled to bind to StdRegProv", Err
End If
' Get current WSUS Server
objReg.GetStringValue HKLM, "SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate", "WUServer", strWUServer
' Get just the FQDN of the WSUS Server
If IsNull(strWUServer) then
strWUServer = ""
ThrowScriptErrorNoAbort "failed to get WU server from registry. ", Err
End If

' Get Version number of WU Agent
Dim oAgentInfo, strVersion
Err.Clear
Set oAgentInfo = CreateObject("Microsoft.Update.AgentInfo")
If Err.Number = 0 Then
strVersion = oAgentInfo.GetInfo("ProductVersionString")
Else
strVersion = ""
ThrowScriptErrorNoAbort "Error getting WU Agent Version info", Err
End If

'' Discover Essentials Managed Computer
Set oEssentialsAgentInstance = oDisc.CreateClassInstance("$MPElement[Name='SCEInternal!Microsoft.SystemCenter.Essentials.EssentialsManagedComputer']$")
'' Add properties
Call oEssentialsAgentInstance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", sTargetComputer)
Call oDisc.AddInstance(oEssentialsAgentInstance)

'' Discover WindowsUpdate Agent
Set oWUAgentInstance = oDisc.CreateClassInstance("$MPElement[Name='Microsoft.SystemCenter.Essentials.WUAgent']$")
Call oWUAgentInstance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", sTargetComputer)
Call oWUAgentInstance.AddProperty("$MPElement[Name='Microsoft.SystemCenter.Essentials.WUAgent']/UpdateServer$", strWUServer)
Call oWUAgentInstance.AddProperty("$MPElement[Name='Microsoft.SystemCenter.Essentials.WUAgent']/Version$", strVersion)

call oDisc.AddInstance(oWUAgentInstance)

'' Discover Relationship
Set oRelCon = oDisc.CreateRelationshipInstance("$MPElement[Name='Microsoft.SystemCenter.Essentials.EssentialsManagedComputerContainsWUAgent']$")
oRelCon.Source = oEssentialsAgentInstance
oRelCon.Target = oWUAgentInstance
Call oDisc.AddInstance(oRelCon)
DoDiscovery = 0
End Function

'*************************************************************************
Class Error
Private m_lNumber
Private m_sSource
Private m_sDescription
Private m_sHelpContext
Private m_sHelpFile
Public Sub Save()
m_lNumber = Err.number
m_sSource = Err.Source
m_sDescription = Err.Description
m_sHelpContext = Err.HelpContext
m_sHelpFile = Err.helpfile
End Sub
Public Sub Raise()
Err.Raise m_lNumber, m_sSource, m_sDescription, m_sHelpFile, m_sHelpContext
End Sub
Public Sub Clear()
m_lNumber = 0
m_sSource = ""
m_sDescription = ""
m_sHelpContext = ""
m_sHelpFile = ""
End Sub
Public Default Property Get Number()
Number = m_lNumber
End Property
Public Property Get Source()
Source = m_sSource
End Property
Public Property Get Description()
Description = m_sDescription
End Property
Public Property Get HelpContext()
HelpContext = m_sHelpContext
End Property
Public Property Get HelpFile()
HelpFile = m_sHelpFile
End Property
End Class

'*************************************************************************
Function ThrowScriptErrorNoAbort(ByVal sMessage, ByVal oErr)
'
' ThrowScriptError :: Creates an event and sends it back to the mom server
'
'*************************************************************************
Dim sErrDescription, sErrNumber
sErrDescription = oErr.Description
sErrNumber = oErr.Number

End Function

'*************************************************************************
Function ThrowScriptError(Byval sMessage, ByVal oErr)
'
' ThrowScriptError :: Creates an event and sends it back to the mom server
'
''*************************************************************************
On Error Resume Next
ThrowScriptErrorNoAbort sMessage, oErr
Quit()
End Function

'*************************************************************************
Function MomCreateObject(ByVal sProgramId)
Dim oError
Set oError = New Error

On Error Resume Next
Set MomCreateObject = CreateObject(sProgramId)
oError.Save
On Error Goto 0

If oError.Number &lt;&gt; 0 Then ThrowScriptError "Unable to create automation object '" &amp; sProgramId &amp; "'", oError
End Function

'*************************************************************************
Function Quit()

WScript.Quit()

End Function
'****************************************************************************
</Script></ScriptBody>
<TimeoutSeconds>300</TimeoutSeconds>
</DataSource>
</Discovery>