''
'' Declare some working variables and then create an empty discovery payload.
''
Dim oAPI, oDiscoveryData, cInst, mInst, bInst, relInst, relInst2
Set oAPI = CreateObject("MOM.ScriptAPI")
set oDiscoveryData = oAPI.CreateDiscoveryData(0, SourceId, ManagedEntityId)
''
'' Now, let's discover the consensus node and set its properties. When done we add it to the discovery packet
''
set cInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='Microsoft.Windows.BranchCache.DistributedCacheClientNode']$")
''
'' Since we are using "contains" - we have to now discover the class instance above us. If it is
'' already discovered, Ops Manager will recognize this as a reference count increase and not a
'' separate discovery because the key property is the same.
''
set mInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='Microsoft.Windows.BranchCache.DistributedCacheGroup']$")
''
'' Now we have to also create an instance of the relationship to link this DistributedCacheClientNode to its parent
''
set relInst = oDiscoveryData.CreateRelationshipInstance("$MPElement[Name='Microsoft.Windows.BranchCache.DistributedCacheGroupContainsDistributedCacheClientNode']$")
relInst.Source = mInst
relInst.Target = cInst
call oDiscoveryData.AddInstance(relInst)
''
'' Now we have to also create an instance of the relationship to link this DistributedCacheGroup to its parent
''
set relInst2 = oDiscoveryData.CreateRelationshipInstance("$MPElement[Name='Microsoft.Windows.BranchCache.BranchOfficeGroupContainsDistributedCacheGroup']$")
relInst2.Source = bInst
relInst2.Target = mInst
call oDiscoveryData.AddInstance(relInst2)
''
'' To force the RMS to re-assign the local agent as the managing agent for the discovered HostedCacheClientNode (cInst)
'' we have to get a reference to the local health service class and then create a SPECIAL SECRET relationship :)
set oHsCnRel = oDiscoveryData.CreateRelationshipInstance("$MPElement[Name='SC!Microsoft.SystemCenter.HealthServiceShouldManageEntity']$")
oHsCnRel.Source = oHealthServiceInstance
oHsCnRel.Target = cInst
call oDiscoveryData.AddInstance(oHsCnRel)
set oHsCnRel2 = oDiscoveryData.CreateRelationshipInstance("$MPElement[Name='SC!Microsoft.SystemCenter.HealthServiceShouldManageEntity']$")
oHsCnRel2.Source = oHealthServiceInstance
oHsCnRel2.Target = mInst
call oDiscoveryData.AddInstance(oHsCnRel2)
''
'' And now we just return the discovery data
''
Call oAPI.Return(oDiscoveryData)</Script></ScriptBody>
<TimeoutSeconds>300</TimeoutSeconds>
</DataSource>
</Discovery>