Обнаружение иерархии узлов клиентов размещенного кэша

Microsoft.Windows.BranchCache.HostedCacheClientNodeHierarchy.Discovery (Discovery)

Обнаружение филиала с размещенным кэшем, к которому относится этот компьютер, по серверу размещенного кэша, заданному в групповой политике.

Knowledge Base article:

Краткое описание

Это правило осуществляет обнаружение филиала с размещенным кэшем, к которому относится этот компьютер, по серверу размещенного кэша, заданному в групповой политике.

Element properties:

TargetMicrosoft.Windows.BranchCache.HostedCacheClientNode
EnabledTrue
Frequency14400
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.Windows.BranchCache.HostedCacheClientNodeHierarchy.Discovery" Enabled="true" Target="Microsoft.Windows.BranchCache.HostedCacheClientNode" ConfirmDelivery="false" Remotable="true" Priority="Normal">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="Microsoft.Windows.BranchCache.HostedCacheClientNode">
<Property TypeID="Microsoft.Windows.BranchCache.ClientSideServiceBase" PropertyID="NodeName"/>
<Property PropertyID="HostedCacheName"/>
<Property PropertyID="GPHostedCacheName"/>
<Property PropertyID="GPHostedCacheNameExists"/>
</DiscoveryClass>
<DiscoveryClass TypeID="Microsoft.Windows.BranchCache.HostedCacheClientGroup">
<Property PropertyID="HostedCacheServerGroupName"/>
</DiscoveryClass>
<DiscoveryClass TypeID="Microsoft.Windows.BranchCache.HostedCacheGroup">
<Property PropertyID="HostedCacheName"/>
</DiscoveryClass>
<DiscoveryClass TypeID="Microsoft.Windows.BranchCache.BranchCacheApp"/>
<DiscoveryRelationship TypeID="Microsoft.Windows.BranchCache.HostedCacheClientGroupContainsHostedCacheClientNode"/>
<DiscoveryRelationship TypeID="Microsoft.Windows.BranchCache.HostedCacheGroupContainsHostedCacheClientGroup"/>
<DiscoveryRelationship TypeID="Microsoft.Windows.BranchCache.BranchCacheAppHostsHostedCacheGroup"/>
</DiscoveryTypes>
<DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedScript.DiscoveryProvider">
<IntervalSeconds>14400</IntervalSeconds>
<SyncTime/>
<ScriptName>BranchCache.HostedCacheClientNodeHierarchy.Discovery.vbs</ScriptName>
<Arguments>$MPElement$ $Target/Id$ $Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$ $Target/Property[Type="Microsoft.Windows.BranchCache.HostedCacheClientNode"]/GPHostedCacheNameExists$ $Target/Property[Type="Microsoft.Windows.BranchCache.HostedCacheClientNode"]/GPHostedCacheName$</Arguments>
<ScriptBody><Script>Option Explicit
SetLocale("en-us")

Function GetStdRegProvObject
Dim strComputer
strComputer = "."
Set GetStdRegProvObject = GetObject("winmgmts:\\" &amp; strComputer &amp; "\root\default:StdRegProv")
End Function

Function GetStringValue(strKeyPath, strValueName)
Const HKEY_LOCAL_MACHINE = &amp;H80000002
Dim objRegistry
Set objRegistry = GetStdRegProvObject
objRegistry.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, GetStringValue
Set objRegistry = Nothing
End Function

Function StringValueExists(strKeyPath, strValueName)
StringValueExists = Not IsNull(GetStringValue(strKeyPath, strValueName))
End Function

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

Dim SourceID, ManagedEntityId, TargetComputer, HostedCache, SingleHostedCache, GPHostedCache, GPHostedCacheExists

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

GPHostedCache = ""
If GPHostedCacheExists = "True" Then
If oArgs.Count &lt; 5 Then
WScript.Quit -1
End If
GPHostedCache = oArgs(4)
End If

HostedCache = ""
Const strConnectionKey = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\PeerDist\HostedCache\Connection"
Const strCurrentVersion = "SOFTWARE\Microsoft\Windows NT\CurrentVersion"

If CDbl(GetStringValue(strCurrentVersion, "CurrentVersion")) &gt;= 6.2 Then
WScript.Quit -1
End If

If GPHostedCacheExists = "False" Then
If StringValueExists(strConnectionKey, "Location") Then
HostedCache = GetStringValue(strConnectionKey, "Location")
SingleHostedCache = HostedCache
End If
End If

''
'' Declare some working variables and then create an empty discovery payload.
''
Dim oAPI, oDiscoveryData, cInst, mInst, bInst, appInst, relInst, relInst2, relInst3

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.HostedCacheClientNode']$")

call cInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", TargetComputer)
call cInst.AddProperty("$MPElement[Name='Microsoft.Windows.BranchCache.ClientSideServiceBase']/NodeName$", TargetComputer)
call cInst.AddProperty("$MPElement[Name='Microsoft.Windows.BranchCache.HostedCacheClientNode']/HostedCacheName$", SingleHostedCache)
call cInst.AddProperty("$MPElement[Name='Microsoft.Windows.BranchCache.HostedCacheClientNode']/GPHostedCacheName$", GPHostedCache)
call cInst.AddProperty("$MPElement[Name='Microsoft.Windows.BranchCache.HostedCacheClientNode']/GPHostedCacheNameExists$", GPHostedCacheExists)

call cInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", TargetComputer)
call oDiscoveryData.AddInstance(cInst)

''
'' 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.HostedCacheClientGroup']$")
If GPHostedCacheExists = "True" Then
call mInst.AddProperty("$MPElement[Name='Microsoft.Windows.BranchCache.HostedCacheClientGroup']/HostedCacheServerGroupName$", GPHostedCache)
call mInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", "HostedCache: "+ GPHostedCache)
Else
call mInst.AddProperty("$MPElement[Name='Microsoft.Windows.BranchCache.HostedCacheClientGroup']/HostedCacheServerGroupName$", HostedCache)
call mInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", "HostedCache: "+ HostedCache)
End If

call oDiscoveryData.AddInstance(mInst)

''
'' Now we have to also create an instance of the relationship to link this HostedCacheClientNode to its parent
''
set relInst = oDiscoveryData.CreateRelationshipInstance("$MPElement[Name='Microsoft.Windows.BranchCache.HostedCacheClientGroupContainsHostedCacheClientNode']$")
relInst.Source = mInst
relInst.Target = cInst
call oDiscoveryData.AddInstance(relInst)

set bInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='Microsoft.Windows.BranchCache.HostedCacheGroup']$")
call bInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", "Hosted Caches")
call bInst.AddProperty("$MPElement[Name='Microsoft.Windows.BranchCache.HostedCacheGroup']/HostedCacheName$", "Hosted Caches")
call oDiscoveryData.AddInstance(bInst)

''
'' Now we have to also create an instance of the relationship to link this HostedCacheGroup to its parent
''
set relInst2 = oDiscoveryData.CreateRelationshipInstance("$MPElement[Name='Microsoft.Windows.BranchCache.HostedCacheGroupContainsHostedCacheClientGroup']$")

relInst2.Source = bInst
relInst2.Target = mInst
call oDiscoveryData.AddInstance(relInst2)

''
'' BranchCacheAppHostsHostedCacheGroup is using containment
'' We must also discover the BranchCacheApp and create that relationship
''

set appInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='Microsoft.Windows.BranchCache.BranchCacheApp']$")
call appInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", "BranchCache")
call oDiscoveryData.AddInstance(appInst)

set relInst3 = oDiscoveryData.CreateRelationshipInstance("$MPElement[Name='Microsoft.Windows.BranchCache.BranchCacheAppHostsHostedCacheGroup']$")

relInst3.Source = appInst
relInst3.Target = bInst
call oDiscoveryData.AddInstance(relInst3)

''
'' 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 :)

Dim oHealthServiceInstance, oHsCnRel, OHsCnRel2

Set oHealthServiceInstance = oDiscoveryData.CreateClassInstance( "$MPElement[Name='SC!Microsoft.SystemCenter.HealthService']$" )
call oHealthServiceInstance.AddProperty ("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", TargetComputer )

call oDiscoveryData.AddInstance(oHealthServiceInstance)

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>