Microsoft.Windows.Server.ClusterDisksMonitoring.ClusterDisk.Discovery.ScriptDataSource (DataSourceModuleType)

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
OutputTypeSystem.Discovery.Data

Member Modules:

ID Module Type TypeId RunAs 
Scheduler DataSource System.Discovery.Scheduler Default
DS ProbeAction Microsoft.Windows.PowerShellDiscoveryProbe Default

Overrideable Parameters:

IDParameterTypeSelector
IntervalSecondsint$Config/IntervalSeconds$
LogSuccessEventbool$Config/LogSuccessEvent$
ScriptGroupIdstring$Config/ScriptGroupId$
TimeoutSecondsint$Config/TimeoutSeconds$

Source Code:

<DataSourceModuleType ID="Microsoft.Windows.Server.ClusterDisksMonitoring.ClusterDisk.Discovery.ScriptDataSource" Accessibility="Internal" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="IntervalSeconds" type="xsd:int"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="LogSuccessEvent" type="xsd:boolean"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ScriptGroupId" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="MPElementID" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TargetID" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TargetComputer" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ClusterName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TimeoutSeconds" type="xsd:int"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="LogSuccessEvent" Selector="$Config/LogSuccessEvent$" ParameterType="bool"/>
<OverrideableParameter ID="ScriptGroupId" Selector="$Config/ScriptGroupId$" ParameterType="string"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="Scheduler" TypeID="System!System.Discovery.Scheduler">
<Scheduler>
<SimpleReccuringSchedule>
<Interval Unit="Seconds">$Config/IntervalSeconds$</Interval>
</SimpleReccuringSchedule>
<ExcludeDates/>
</Scheduler>
</DataSource>
<ProbeAction ID="DS" TypeID="Windows!Microsoft.Windows.PowerShellDiscoveryProbe">
<ScriptName>Microsoft.Windows.Server.DiscoverClusterDisks.ps1</ScriptName>
<ScriptBody><Script>

param ($mblnLogSuccessEvent, $mstrIdentifier, $strSourceID, $strManagedEntityId, $strTargetComputer, $strClusterName)

$SCRIPT_VERSION = "1.01"
$LOG_SUCCESS_EVENT_PARAMETER_NAME = "LogSuccessEvent"
$MP_ELEMENT_PARAMETER_NAME = "MP Element"
$MANAGED_ENTITY_ID_PARAMETER_NAME = "Managed Entity"
$TARGET_COMPUTER_PARAMETER_NAME = "Target Computer"
$CLUSTER_NAME_PARAMETER_NAME = "Cluster Name"

#WMI constants
$WMI_MSCLUSTER_NAMESPACE = "root\MSCluster"
$WMI_CIMV2_NAMESPACE = "root\cimv2"
$WMI_MSCLUSTER_CLUSTER_RESOURCE = "MSCluster_Resource"
$WMI_CLUSTER_RESOURCE_TO_DISK_ASSOCIATOR_CLASS = "MSCluster_ResourceToDisk"
$WMI_CLUSTER_DISKPARTITION_TO_DISK_ASSOCIATOR_CLASS = "MSCluster_DiskToDiskPartition"

$WMI_MSCLUSTER_RESOURCEGROUP = "MSCluster_ResourceGroup"
$WMI_MSCLUSTER_RESOURCEGROUP_TO_RESOURCE = "MSCluster_ResourceGroupToResource"

$WMI_MSCLUSTER_CLUSTER_CLASS = "MSCluster_Cluster"
$WMI_NAME_PROPERTY_NAME = "Name"
$WMI_PATH_PROPERTY_NAME = "Path"
$WMI_FILESYSTEM_PROPERTY_NAME = "FileSystem"
$WMI_TOTALSIZE_PROPERTY_NAME = "TotalSize"
$WMI_VOLUMELABEL_PROPERTY_NAME = "VolumeLabel"


#State property bag constants
$STATE_PROPERTY_NAME = "State"
$STATE_DESCRIPTION_NAME = "Description"
$STATE_PARTITION_FS_GOOD = "FSGOOD"
$STATE_PARTITION_FS_WARNING = "FSWARNING"
$STATE_PARTITION_FS_BAD = "FSBAD"
$STATE_DIRTY_BIT_GOOD = "DBGOOD"
$STATE_DIRTY_BIT_BAD = "DBBAD"

#State property bag constants

#Event constants
$EVENT_TYPE_SUCCESS = 0
$EVENT_TYPE_ERROR = 1
$EVENT_TYPE_WARNING = 2
$EVENT_TYPE_INFORMATION = 4

$EVENT_ID_SUCCESS = 1000 #Use IDs in the range 1 - 1000
$EVENT_ID_SCRIPTERROR = 999 #Then you can use eventcreate.exe to test the MP

#Scripting.FileSystemObject constants
$FOR_READING = 1 #Open a file for reading only. You can#t write to this file.
$FOR_WRITING = 2 #Open a file for writing.
$FOR_APPENDING = 8 #Open a file and write to the end of the file.
$SCRIPT_SUCCESS = 0
$SCRIPT_WITH_ERROR = 1

$WIN_SRV_2012_OSVer = "6.2"
#******************************************************************************
# FUNCTION: CheckByOSCurrentVersion
# DESCRIPTION: Returns True if the Registry Key for CurrentVersion
# is equal the target OS Versions Number.
# RETURNS: Boolean: True, if build is greater or equal than the given number
#******************************************************************************
function CheckByOSCurrentVersion()
{
$strCurrentOSVer = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\"
$strCurrentOSVer = $strCurrentOSVer.CurrentVersion
$CheckByOSCurrentVersion = $false
if($strCurrentOSVer -ge $WIN_SRV_2012_OSVer){
$CheckByOSCurrentVersion = $true
}else{
$CheckByOSCurrentVersion = $false
}
return $CheckByOSCurrentVersion;
}

$useCIM = CheckByOSCurrentVersion

#Global vars
#$mblnLogSuccessEvent #As String(ToBoolean) (passed in as parameter of script)
#$mstrIdentifier #As String (passed in as parameter of script)

#*********************************************************************************************
# PROCEDURE: Main
# DESCRIPTION: Reads the script parameters and creates the cluster disks discovery data.
# PARAMETERS: void
#*********************************************************************************************
Function Main()
{

# Targeted at Microsoft.Windows.Cluster.VirtualServer (based on Microsoft.Windows.Server.Computer)
$objMomScriptAPI = New-Object -comObject MOM.ScriptAPI

#Create new discovery data object
if ([System.Convert]::ToBoolean($mblnLogSuccessEvent) -eq $true)
{
$objMomScriptAPI.LogScriptEvent((Split-Path $MyInvocation.ScriptName -Leaf), $EVENT_ID_SUCCESS, $EVENT_TYPE_INFORMATION,"before create discovery data")
}

$objDiscoveryData = $objMomScriptAPI.CreateDiscoveryData(0, $strSourceID, $strManagedEntityId)

#Discover instances
$intSuccess = DiscoverClusterDisks $strTargetComputer $strClusterName $objDiscoveryData

if ($intSuccess -eq $SCRIPT_SUCCESS)
{
if ([System.Convert]::ToBoolean($mblnLogSuccessEvent) -eq $true)
{
$objMomScriptAPI.LogScriptEvent((Split-Path $MyInvocation.ScriptName -Leaf), $EVENT_ID_SUCCESS, $EVENT_TYPE_INFORMATION, "-- Cluster Disks Discovery Script -- Script executed successfully.")
}
#Return discovery data
$objDiscoveryData
}
else
{
$objMomScriptAPI.LogScriptEvent((Split-Path $MyInvocation.ScriptName -Leaf), $EVENT_ID_SCRIPTERROR, $EVENT_TYPE_WARNING, "-- Cluster Disks Discovery Script -- An error occurred while running the script.")
}
}

#****************************************************************************************************************
# FUNCTION: DiscoverClusterDisks
# DESCRIPTION: Discover instances of the class #Microsoft.Windows.Server.ClusterDisksMonitoring.ClusterDisk# using WMI.
# PARAMETERS: IN String strTargetComputer: principal name of the targeted #Microsoft.Windows.Cluster.VirtualServer# instance.
# IN String strClusterName: the cluster containing the cluster shared volume
# OUT Object objDiscoveryData: initialised DiscoveryData instance
# RETURNS: Integer: 0 if successful and 1 if fails
#****************************************************************************************************************
Function DiscoverClusterDisks($strTargetComputer, $strClusterName, $objDiscoveryData) #As Integer
{
$blnUseResource = $false

#Connect to WMI NS \\.\root\MSCluster
$error.Clear()
# !!! Refactoring comment:
# Original VBScript only tries to connect to the namespace. Piping to get only the first one saves time.
if($useCIM){
$oWMI = Get-CimClass -Namespace $WMI_MSCLUSTER_NAMESPACE -ErrorAction SilentlyContinue | select -First 1
}else{
$oWMI = Get-WMIObject -Namespace $WMI_MSCLUSTER_NAMESPACE -Class $WMI_MSCLUSTER_CLUSTER_RESOURCE -ErrorAction SilentlyContinue | select -First 1
}
if ($error.Count -eq 0)
{
if($useCIM){
$objClusterResNetworks = Get-CimInstance -Namespace $WMI_MSCLUSTER_NAMESPACE -Query ("select * from " + $WMI_MSCLUSTER_CLUSTER_RESOURCE + " where Type = 'Network Name'") -ErrorAction SilentlyContinue
}else{
$objClusterResNetworks = Get-WMIObject -Namespace $WMI_MSCLUSTER_NAMESPACE -Query ("select * from " + $WMI_MSCLUSTER_CLUSTER_RESOURCE + " where Type = 'Network Name'") -ErrorAction SilentlyContinue
}
if ($error.Count -gt 0)
{
return $SCRIPT_WITH_ERROR
}

foreach ($objClusterResNet in $objClusterResNetworks)
{
$strDnsName = $objClusterResNet.PrivateProperties.DnsName

#Get the hostname of the target computer from its principal name
if ($strTargetComputer.IndexOf(".") -gt 0)
{
$strTargetComputerShortName = $strTargetComputer.Substring(0, $strTargetComputer.IndexOf("."))
}
else
{
$strTargetComputerShortName = $strTargetComputer
}
$blnUseResource = ($strTargetComputerShortName -ieq $strDnsName)

if ($blnUseResource)
{
foreach ($objResGroupAsc in (Get-CimAssociatedInstance -InputObject $objClusterResNet -Association $WMI_MSCLUSTER_RESOURCEGROUP_TO_RESOURCE))
{
$strGroupName = $objResGroupAsc.Name
}
}
}

$error.Clear()
if($useCIM){
$objResourceGroups = Get-CimInstance -Namespace $WMI_MSCLUSTER_NAMESPACE -Query ("select * from " + $WMI_MSCLUSTER_RESOURCEGROUP) -ErrorAction SilentlyContinue
}else{
$objResourceGroups = Get-WMIObject -Namespace $WMI_MSCLUSTER_NAMESPACE -Query ("select * from " + $WMI_MSCLUSTER_RESOURCEGROUP) -ErrorAction SilentlyContinue
}

if ($error.Count -gt 0)
{
return $SCRIPT_WITH_ERROR
}

foreach ($objResourceGroup in $objResourceGroups)
{
if ($objResourceGroup.Name -ieq $strGroupName)
{
if($useCIM){
$objClusterResources =(Get-CimAssociatedInstance -InputObject $objResourceGroup -Association $WMI_MSCLUSTER_RESOURCEGROUP_TO_RESOURCE)
}else{
$objClusterResources = $objResourceGroup.GetRelated("MSCluster_Resource")
}
foreach ($objClusterResource in $objClusterResources)
{
#Get the associated disk
if($useCIM){
$objClusterDisks = (Get-CimAssociatedInstance -InputObject $objClusterResource -Association $WMI_CLUSTER_RESOURCE_TO_DISK_ASSOCIATOR_CLASS)
}else{
$objClusterDisks = $objClusterResource.GetRelated("MSCluster_Disk")
}
foreach ($objClusterDisk in $objClusterDisks)
{
#Get the associated disk partition
if($useCIM){
$objClusterDiskPartitions = (Get-CimAssociatedInstance -InputObject $objClusterDisk -Association $WMI_CLUSTER_DISKPARTITION_TO_DISK_ASSOCIATOR_CLASS)
}else{
$objClusterDiskPartitions = $objClusterDisk.GetRelated("MSCluster_DiskPartition")
}
foreach ($objClusterDiskPartition in $objClusterDiskPartitions)
{
$intSuc = CreateDiscoveryData $objClusterDisk $objClusterDiskPartition $objClusterResource $strTargetComputer $strClusterName $objDiscoveryData
}
}
}

if ($error.Count -gt 0)
{
return $SCRIPT_WITH_ERROR
}
}
else
{
$objToReturn = $SCRIPT_SUCCESS
}
}

if($intSuc -eq $null)
{
return $objToReturn
}
return $intSuc
}
}

#****************************************************************************************************************
# FUNCTION: CreateDiscoveryData
# DESCRIPTION: Create discovery data for
# &lt;ClassType ID="Microsoft.Windows.Server.ClusterDisksMonitoring.ClusterDisk" Accessibility="Internal" Abstract="false" Base="Windows!Microsoft.Windows.ApplicationComponent" Hosted="true" Singleton="false"&gt;
# &lt;Property ID="ClusterResourceName" Type="string" Key="true" CaseSensitive="false" Length="256" MinLength="0" /&gt;
# &lt;Property ID="ClusterDiskName" Type="string" Key="false" CaseSensitive="false" Length="256" MinLength="0" /&gt;
# &lt;Property ID="PartitionName" Type="string" Key="false" CaseSensitive="false" Length="256" MinLength="0" /&gt;
# &lt;Property ID="PartitionFileSystem" Type="string" Key="false" CaseSensitive="false" Length="256" MinLength="0" /&gt;
# &lt;Property ID="PartitionSize" Type="int" Key="false" /&gt;
# &lt;Property ID="ClusterName" Type="string" Key="false" CaseSensitive="false" Length="256" MinLength="0" /&gt;
# &lt;Property ID="VolumeLabel" Type="string" Key="false" CaseSensitive="false" Length="256" MinLength="0" /&gt;
# &lt;/ClassType&gt;
#
# PARAMETERS: IN Object objClusterResource: the cluster disks as SWbemObject of type MSCluster_Disk.
# IN Object objClusterDiskPartition: the associated disk partition as SWbemObject of type MSCluster_DiskPartition.
# IN Object objClusterResource: the associated cluster resource as SWbemObject of type MSCluster_Resource.
# IN String strTargetComputer: the principal name of the targeted cluster virtual server hosting the cluster shared volume,
# i.e. the cluster name and not the current owner!
# IN String strClusterName: the cluster containing the cluster shared volume
# OUT Object objDiscoveryData: initialised DiscoveryData instance
# RETURNS: Integer: 0 if successful or 1 if Error
#****************************************************************************************************************
Function CreateDiscoveryData($objClusterDisk, $objClusterDiskPartition, $objClusterResource,
$strTargetComputer, $strClusterName, $objDiscoveryData) #As Integer
{
$error.Clear()
$ErrorActionPreference = 'SilentlyContinue' # Scoped only to function

#Create the cluster shared volume instance hosted on the targeted cluster virtual server
$objCSVInstance = $objDiscoveryData.CreateClassInstance("$MPElement[Name='Microsoft.Windows.Server.ClusterDisksMonitoring.ClusterDisk']$")

#PrincipalName (host, key)
$objCSVInstance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $strTargetComputer)

#ClusterSharedVolumeName (key)
$objCSVInstance.AddProperty("$MPElement[Name='Microsoft.Windows.Server.ClusterDisksMonitoring.ClusterDisk']/ClusterResourceName$", ($objClusterResource.$WMI_NAME_PROPERTY_NAME + "_" + $objClusterDiskPartition.$WMI_PATH_PROPERTY_NAME))

#FriendlyVolumeName
$objCSVInstance.AddProperty("$MPElement[Name='Microsoft.Windows.Server.ClusterDisksMonitoring.ClusterDisk']/ClusterDiskName$", $objClusterDisk.$WMI_NAME_PROPERTY_NAME)

#PartitionName
$objCSVInstance.AddProperty("$MPElement[Name='Microsoft.Windows.Server.ClusterDisksMonitoring.ClusterDisk']/PartitionName$", $objClusterDiskPartition.$WMI_PATH_PROPERTY_NAME)

#PartitionFileSystem
$objCSVInstance.AddProperty("$MPElement[Name='Microsoft.Windows.Server.ClusterDisksMonitoring.ClusterDisk']/PartitionFileSystem$", $objClusterDiskPartition.$WMI_FILESYSTEM_PROPERTY_NAME)

#PartitionSize
$objCSVInstance.AddProperty("$MPElement[Name='Microsoft.Windows.Server.ClusterDisksMonitoring.ClusterDisk']/PartitionSize$", $objClusterDiskPartition.$WMI_TOTALSIZE_PROPERTY_NAME)

#ClusterName
$objCSVInstance.AddProperty("$MPElement[Name='Microsoft.Windows.Server.ClusterDisksMonitoring.ClusterDisk']/ClusterName$", $strClusterName)

#VolumeLabel
$objCSVInstance.AddProperty("$MPElement[Name='Microsoft.Windows.Server.ClusterDisksMonitoring.ClusterDisk']/VolumeLabel$", $objClusterDiskPartition.$WMI_VOLUMELABEL_PROPERTY_NAME)

if ($error.Count -gt 0)
{
return $SCRIPT_WITH_ERROR
}

$objDiscoveryData.AddInstance($objCSVInstance)
return $SCRIPT_SUCCESS

}

Main</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>mblnLogSuccessEvent</Name>
<Value>$Config/LogSuccessEvent$</Value>
</Parameter>
<Parameter>
<Name>mstrIdentifier</Name>
<Value>$Config/ScriptGroupId$</Value>
</Parameter>
<Parameter>
<Name>strSourceID</Name>
<Value>$Config/MPElementID$</Value>
</Parameter>
<Parameter>
<Name>strManagedEntityId</Name>
<Value>$Config/TargetID$</Value>
</Parameter>
<Parameter>
<Name>strTargetComputer</Name>
<Value>$Config/TargetComputer$</Value>
</Parameter>
<Parameter>
<Name>strClusterName</Name>
<Value>$Config/ClusterName$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="DS">
<Node ID="Scheduler"/>
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Discovery.Data</OutputType>
</DataSourceModuleType>