Replicated Folder Volumes Discovery (Windows Server 2008 R2)

Microsoft.Windows.FileServer.DFSR.2008R2.VolumeDiscovery (Discovery)

This object discovers volumes hosting replicated folders on computers running Windows Server 2008 R2.

Knowledge Base article:

Summary

This object discovers volumes hosting replicated folders on computers running Windows Server 2008 R2. It does so by querying the DfsrVolumeInfo WMI class.

Configuration

Users with Author or Administrator permissions in Operations Manager can use overrides to change the following parameters:

Additional

Element properties:

TargetMicrosoft.Windows.FileServer.DFSR.2008R2.Service
EnabledTrue
Frequency14400
RemotableFalse

Object Discovery Details:

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

Member Modules:

ID Module Type TypeId RunAs 
Microsoft.Windows.TimedScript.DiscoveryProvider DataSource Microsoft.Windows.TimedScript.DiscoveryProvider Microsoft.Windows.FileServer.DFSR.MonitoringAccount

Source Code:

<Discovery ID="Microsoft.Windows.FileServer.DFSR.2008R2.VolumeDiscovery" Enabled="true" Target="Microsoft.Windows.FileServer.DFSR.2008R2.Service" ConfirmDelivery="false" Remotable="true" Priority="Normal">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="DFSRLib!Microsoft.Windows.FileServer.DFSR.Volume">
<Property TypeID="DFSRLib!Microsoft.Windows.FileServer.DFSR.Volume" PropertyID="IsClustered"/>
<Property TypeID="DFSRLib!Microsoft.Windows.FileServer.DFSR.Volume" PropertyID="ClusterResourceName"/>
<Property TypeID="DFSRLib!Microsoft.Windows.FileServer.DFSR.Volume" PropertyID="State"/>
<Property TypeID="DFSRLib!Microsoft.Windows.FileServer.DFSR.Volume" PropertyID="DatabasePath"/>
<Property TypeID="DFSRLib!Microsoft.Windows.FileServer.DFSR.Volume" PropertyID="VolumeGUID"/>
<Property TypeID="System!System.Entity" PropertyID="DisplayName"/>
<Property TypeID="DFSRLib!Microsoft.Windows.FileServer.DFSR.Volume" PropertyID="ClusterGroupName"/>
</DiscoveryClass>
<DiscoveryRelationship TypeID="DFSRLib!Microsoft.Windows.FileServer.DFSR.Service.Contains.Volumes"/>
</DiscoveryTypes>
<DataSource ID="Microsoft.Windows.TimedScript.DiscoveryProvider" RunAs="DFSRLib!Microsoft.Windows.FileServer.DFSR.MonitoringAccount" TypeID="Windows!Microsoft.Windows.TimedScript.DiscoveryProvider">
<IntervalSeconds>14400</IntervalSeconds>
<SyncTime/>
<ScriptName>VolumesDiscovery2008R2.vbs</ScriptName>
<Arguments>0 $MPElement$ $Target/Id$ $Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$ $Target/Property[Type="DFSRLib!Microsoft.Windows.FileServer.DFSR.Service"]/IsVirtualNode$</Arguments>
<ScriptBody><Script>Option Explicit

On Error Resume Next

Dim SourceType, SourceID, ManagedEntityId, oArgs, oAPI, sDfsrServerName, VolumeInfo, VolumeInfoList, volumeQuery
Dim objWMIService, oVolumeConfig, oVolumeConfigCollection, ReplicatedFolderList, validVolumeConfig

SetLocale("en-us")

Set oAPI = CreateObject("MOM.ScriptAPI")
Set oArgs = WScript.Arguments
if oArgs.Count &lt; 3 Then
call oAPI.LogScriptEvent("VolumesDiscovery2008R2.vbs", 100, 1, "Expected 3 arguments. There were only " &amp; oArgs.Count &amp; " arguments. Exiting script.")
Wscript.Quit -1
End If

Dim oDiscData, oDfsrServer, stateStr, oRel, oDfsrServerRole, IsVirtualNode, NetworkNameClusterGroup, NetworkResourceName, IsCoreResource

SourceType = oArgs(0)
SourceId = oArgs(1)
ManagedEntityId = oArgs(2)
sDfsrServerName = oArgs(3)

if (oArgs.Count = 5) then
IsVirtualNode = oArgs(4)
else
IsVirtualNode = "False"
end if

NetworkResourceName = "N/A"
IsCoreResource = "False"
NetworkNameClusterGroup = "N/A"

Dim objClusterWMI, oResourceInfoList, oResourceInfo, oClusterGroupList, oClusterGroup

set oDiscData = oAPI.CreateDiscoveryData(SourceType, SourceId, ManagedEntityId)

if (isVirtualNode = "True") then

Set objClusterWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &amp; sDfsrServerName &amp; "\root\mscluster")
if Err.Number &lt;&gt; 0 then
strErr = "Unable to connect to local mscluster WMI provider. Error: 0x" &amp; Hex(Err.Number) &amp; " " &amp; Err.Description
WScript.Echo strErr
Wscript.Quit -1
End If

Set oResourceInfoList = objClusterWMI.ExecQuery ("Select Name, CoreResource from MSCluster_Resource Where PrivateProperties.DnsName='" &amp; Left(sDfsrServerName, InStr(sDfsrServerName, ".")-1) &amp; "'")
if Err.Number &lt;&gt; 0 then
strErr = "Unable to query MSCluster_Resource from local mscluster WMI provider. Error: 0x" &amp; Hex(Err.Number) &amp; " " &amp; Err.Description
WScript.Echo strErr
Wscript.Quit -1
End If

for each oResourceInfo in oResourceInfoList

NetworkResourceName = oResourceInfo.Name
IsCoreResource = oResourceInfo.CoreResource

Set oClusterGroupList = objClusterWMI.ExecQuery ("Select GroupComponent from MSCluster_ResourceGroupToResource Where PartComponent='MSCluster_Resource.Name=" &amp; Chr(34) &amp; oResourceInfo.Name &amp; Chr(34) &amp; "'")
if Err.Number &lt;&gt; 0 then
strErr = "Unable to query MSCluster_ResourceGroupToResource from local mscluster WMI provider. Error: 0x" &amp; Hex(Err.Number) &amp; " " &amp; Err.Description
WScript.Echo strErr
Wscript.Quit -1
End If

for each oClusterGroup in oClusterGroupList

NetworkNameClusterGroup = Replace(Right(oClusterGroup.GroupComponent, Len(oClusterGroup.GroupComponent) - InStr(oClusterGroup.GroupComponent, CStr(Chr(34)) )), CStr(Chr(34)), "")

Exit For
Next

Exit For
Next

Rem Check if any of the disk in this cluster group are not online. If so then the data returned by DFSR might not be complete then mark it as snapshot

Rem Get list of not online disk resources

Set oResourceInfoList = objClusterWMI.ExecQuery ("Select Name from MSCluster_Resource Where State &lt;&gt; 2 and ResourceClass = 1")
if Err.Number &lt;&gt; 0 then
strErr = "Unable to query MSCluster_Resource for not online disks from local mscluster WMI provider. Error: 0x" &amp; Hex(Err.Number) &amp; " " &amp; Err.Description
WScript.Echo strErr
Wscript.Quit -1
End If

for each oResourceInfo in oResourceInfoList
Dim DiskGroupName

Rem check if they belong to the same group

Set oClusterGroupList = objClusterWMI.ExecQuery ("Select GroupComponent from MSCluster_ResourceGroupToResource Where PartComponent='MSCluster_Resource.Name=" &amp; Chr(34) &amp; oResourceInfo.Name &amp; Chr(34) &amp; "'")
if Err.Number &lt;&gt; 0 then
strErr = "Unable to query disk group name against MSCluster_ResourceGroupToResource from local mscluster WMI provider. Error: 0x" &amp; Hex(Err.Number) &amp; " " &amp; Err.Description
WScript.Echo strErr
Wscript.Quit -1
End If

for each oClusterGroup in oClusterGroupList
DiskGroupName = Replace(Right(oClusterGroup.GroupComponent, Len(oClusterGroup.GroupComponent) - InStr(oClusterGroup.GroupComponent, CStr(Chr(34)) )), CStr(Chr(34)), "")

Exit For
Next

if DiskGroupName = NetworkNameClusterGroup then
Rem we found a not online disk in the group

oDiscData.IsSnapshot=false

Exit For
End if
Next
end if

set oDfsrServerRole = oDiscData.CreateClassInstance("$MPElement[Name='Microsoft.Windows.FileServer.DFSR.2008R2.Service']$")

call oDfsrServerRole.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", sDfsrServerName)

Call oDiscData.AddInstance(oDfsrServerRole)

if IsCoreResource = "False" then

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &amp; sDfsrServerName &amp; "\root\microsoftdfs")
if Err.Number &lt;&gt; 0 then
strErr = "Unable to connect to local DFSR WMI provider. Error: 0x" &amp; Hex(Err.Number) &amp; " " &amp; Err.Description
WScript.Echo strErr
Wscript.Quit -1
End If

volumeQuery = "Select VolumeGuid, VolumePath, IsClustered, ClusterDiskResName, DatabasePath from DfsrVolumeConfig where IsClustered = " &amp; IsVirtualNode

Set oVolumeConfigCollection = objWMIService.ExecQuery(volumeQuery)
if Err.Number &lt;&gt; 0 then
strErr = "Unable to query DfsrVolumeConfig from local DFSR WMI provider. Error: 0x" &amp; Hex(Err.Number) &amp; " " &amp; Err.Description
Wscript.Echo strErr
Wscript.Quit -1
End If

for each oVolumeConfig in oVolumeConfigCollection

Dim diskClusterGroupName

diskClusterGroupName = "N/A"
stateStr = "UNINITIALIZED"
validVolumeConfig = true

if (IsVirtualNode = "True") then
REM Make sure that the disk resource belong to same group as the Network Name group

Set objClusterWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &amp; sDfsrServerName &amp; "\root\mscluster")
if Err.Number &lt;&gt; 0 then
strErr = "Unable to connect to local mscluster WMI provider. Error: 0x" &amp; Hex(Err.Number) &amp; " " &amp; Err.Description
WScript.Echo strErr
Rem Wscript.Quit -1
oDiscData.IsSnapshot=false
Else
Set oClusterGroupList = objClusterWMI.ExecQuery ("Select GroupComponent from MSCluster_ResourceGroupToResource Where PartComponent='MSCluster_Resource.Name=" &amp; Chr(34) &amp; oVolumeConfig.ClusterDiskResName &amp; Chr(34) &amp; "'")
if Err.Number &lt;&gt; 0 then
strErr = "Unable to query MSCluster_ResourceGroupToResource from local mscluster WMI provider. Error: 0x" &amp; Hex(Err.Number) &amp; " " &amp; Err.Description
Wscript.Echo strErr
Rem Wscript.Quit -1
oDiscData.IsSnapshot=false
Else
for each oClusterGroup in oClusterGroupList

diskClusterGroupName = Replace(Right(oClusterGroup.GroupComponent, Len(oClusterGroup.GroupComponent) - InStr(oClusterGroup.GroupComponent, CStr(Chr(34)) )), CStr(Chr(34)), "")

Exit For
Next
End If
End if
end if

if (diskClusterGroupName = NetworkNameClusterGroup) then
set oDfsrServer = oDiscData.CreateClassInstance("$MPElement[Name='DFSRLib!Microsoft.Windows.FileServer.DFSR.Volume']$")

call oDfsrServer.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", sDfsrServerName)
call oDfsrServer.AddProperty("$MPElement[Name='DFSRLib!Microsoft.Windows.FileServer.DFSR.Volume']/VolumeGUID$", oVolumeConfig.VolumeGuid)
call oDfsrServer.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", Mid(oVolumeConfig.VolumePath, 5))
call oDfsrServer.AddProperty("$MPElement[Name='DFSRLib!Microsoft.Windows.FileServer.DFSR.Volume']/DatabasePath$", Mid(oVolumeConfig.DatabasePath, 5))
call oDfsrServer.AddProperty("$MPElement[Name='DFSRLib!Microsoft.Windows.FileServer.DFSR.Volume']/IsClustered$", oVolumeConfig.IsClustered)
call oDfsrServer.AddProperty("$MPElement[Name='DFSRLib!Microsoft.Windows.FileServer.DFSR.Volume']/ClusterGroupName$", diskClusterGroupName)

if (CStr(oVolumeConfig.IsClustered) = "True") then
call oDfsrServer.AddProperty("$MPElement[Name='DFSRLib!Microsoft.Windows.FileServer.DFSR.Volume']/ClusterResourceName$", oVolumeConfig.ClusterDiskResName)
else
call oDfsrServer.AddProperty("$MPElement[Name='DFSRLib!Microsoft.Windows.FileServer.DFSR.Volume']/ClusterResourceName$", "N/A")
end if

Set VolumeInfoList = objWMIService.ExecQuery ("Select State from DfsrVolumeInfo Where VolumeGuid ='" &amp; oVolumeConfig.VolumeGuid &amp; "'")
if Err.Number &lt;&gt; 0 then
strErr = "Unable to query DfsrVolumeInfo from local DFSR WMI provider. Error: 0x" &amp; Hex(Err.Number) &amp; " " &amp; Err.Description
WScript.Echo strErr
Err.Clear
oDiscData.IsSnapshot=false
Else
for each VolumeInfo in VolumeInfoList
Select Case VolumeInfo.State

Case 0
stateStr = "INITIALIZED"
Case 1
stateStr = "SHUTTING DOWN"
Case 2
stateStr = "IN ERROR"
Case 3
stateStr = "AUTO RECOVERY"
Case else
stateStr = "INVALID STATE"

End Select
Next
End If


REM
REM DFSR in some cases leaves the volume manager running and also fail to delete volume XML. when really there is no replicated
REM folders remaining and are all deleted. To handle this case, we will query DfsrReplicatedFolderConfig for folders with
REM volume GUID matching and if there are none then we will not add this volume instance, as this is just a stale object
REM

Set ReplicatedFolderList = objWMIService.ExecQuery ("Select Enabled from DfsrReplicatedFolderConfig Where ContainerComputerName ='" &amp; Left(sDfsrServerName, InStr(sDfsrServerName, ".")-1) &amp; "' and VolumeGuid ='" &amp; oVolumeConfig.VolumeGuid &amp; "'")
If Err.Number &lt;&gt; 0 then
strErr = "Unable to query DfsrReplicatedFolderConfig from local DFSR WMI provider. Error: 0x" &amp; Hex(Err.Number) &amp; " " &amp; Err.Description
WScript.Echo strErr
Err.Clear
oDiscData.IsSnapshot=false
Else
If ReplicatedFolderList.Count = 0 then
validVolumeConfig = false
End If
End If


If validVolumeConfig = true then
call oDfsrServer.AddProperty("$MPElement[Name='DFSRLib!Microsoft.Windows.FileServer.DFSR.Volume']/State$", stateStr)

Call oDiscData.AddInstance(oDfsrServer)

Set oRel = oDiscData.CreateRelationshipInstance("$MPElement[Name='DFSRLib!Microsoft.Windows.FileServer.DFSR.Service.Contains.Volumes']$")

oRel.Source = oDfsrServerRole
oRel.Target = oDfsrServer

Call oDiscData.AddInstance(oRel)
End If
End If
Next
End If

Call oAPI.Return(oDiscData)</Script></ScriptBody>
<TimeoutSeconds>900</TimeoutSeconds>
</DataSource>
</Discovery>