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

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
OutputTypeSystem.Discovery.Data

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource System.Discovery.Scheduler Default
PsProbe 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="DS" TypeID="System!System.Discovery.Scheduler">
<Scheduler>
<SimpleReccuringSchedule>
<Interval Unit="Seconds">$Config/IntervalSeconds$</Interval>
</SimpleReccuringSchedule>
<ExcludeDates/>
</Scheduler>
</DataSource>
<ProbeAction ID="PsProbe" TypeID="Windows!Microsoft.Windows.PowerShellDiscoveryProbe">
<ScriptName>Microsoft.Windows.Server.DiscoverClusterDisks.ps1</ScriptName>
<ScriptBody><Script>

param ($mblnLogSuccessEvent, $mstrIdentifier, $strSourceID, $strManagedEntityId, $strTargetComputer, $strClusterName)
$SCRIPT_VERSION = "1.05"
$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"

#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

$SCRIPT_SUCCESS = 0
$SCRIPT_WITH_ERROR = 1
$ClusterDiskClassName = "$MPElement[Name='Microsoft.Windows.Server.ClusterDisksMonitoring.ClusterDisk.NewOS']$"

#*********************************************************************************************
# PROCEDURE: Main
# DESCRIPTION: Reads the script parameters and creates the cluster disks discovery data.
# PARAMETERS: void
#*********************************************************************************************
Function Main()
{
$ErrorActionPreference = 'SilentlyContinue'
$error.Clear()

# Targeted at Microsoft.Windows.Cluster.VirtualServer (based on Microsoft.Windows.Server.Computer)
$objMomScriptAPI = New-Object -ComObject Mom.ScriptAPI -ErrorAction SilentlyContinue

if ($null -eq $objMomScriptAPI -or $error.Count -ne 0)
{
exit -1
}

$useCIM = CheckCmdLets
$mblnLogSuccessEvent = Convert-ToBoolean -sBool $mblnLogSuccessEvent

#Create new discovery data object
$error.Clear()

$objDiscoveryData = $objMomScriptAPI.CreateDiscoveryData(0, $strSourceID, $strManagedEntityId)
if ($error.Count -ne 0)
{
$Message = "-- Cluster Disks Discovery Script -- An error occurred while creating Discovery Data Object."
LogScriptEvent -LogType 0 -EventId $EVENT_ID_SCRIPTERROR -EventLevel $EVENT_TYPE_WARNING -Message $Message -objMomScriptAPI $objMomScriptAPI
exit -1
}

$strClusterGroupName = $strClusterName
$strClusterName = Get-ClusterName -useCim $useCIM
If ([string]::IsNullOrEmpty($strClusterName) )
{
$Message = "-- Cluster Disks Discovery Script -- An error occurred while getting Cluster Name."
LogScriptEvent -LogType 0 -EventId $EVENT_ID_SCRIPTERROR -EventLevel $EVENT_TYPE_WARNING -Message $Message -objMomScriptAPI $objMomScriptAPI
exit -1
}

#Discover instances
$intSuccess = DiscoverClusterDisks -strTargetComputer $strTargetComputer -strClusterName $strClusterName -strClusterGroupName $strClusterGroupName -objDiscoveryData $objDiscoveryData -useCIM $useCIM

if ($intSuccess -eq $SCRIPT_SUCCESS)
{
if ($mblnLogSuccessEvent -eq $true)
{
$Message = "-- Cluster Disks Discovery Script -- Script executed successfully."
LogScriptEvent -LogType 0 -EventId $EVENT_ID_SUCCESS -EventLevel $EVENT_TYPE_INFORMATION -Message $Message -objMomScriptAPI $objMomScriptAPI

}
#Return discovery data
$objDiscoveryData
}
else
{
$Message = "-- Cluster Disks Discovery Script -- An error occurred while running the script."
LogScriptEvent -LogType 0 -EventId $EVENT_ID_SCRIPTERROR -EventLevel $EVENT_TYPE_WARNING -Message $Message -objMomScriptAPI $objMomScriptAPI
}
}

Function DiscoverClusterDisksCim($strTargetComputer, $strClusterName,$strClusterGroupName, $objDiscoveryData) #As Integer
{
$ErrorActionPreference = 'SilentlyContinue'
$error.Clear()
$iResult = $SCRIPT_WITH_ERROR

$oWMI = Get-CimClass -Namespace $WMI_MSCLUSTER_NAMESPACE -ErrorAction SilentlyContinue | select -First 1

if ($error.Count -ne 0)
{
return $iResult
}

if ([string]::IsNullOrEmpty($strClusterGroupName))
{
$objClusterResNetworks = Get-CimInstance -Namespace $WMI_MSCLUSTER_NAMESPACE -ClassName $WMI_MSCLUSTER_CLUSTER_RESOURCE -Filter "Type = 'Network Name'" -ErrorAction SilentlyContinue

if ($error.Count -ne 0)
{
return $iResult
}

$strTargetComputerShortName = Get-ComputerName -strTargetComputer $strTargetComputer
foreach ($objClusterResNet in $objClusterResNetworks)
{
if ($error.Count -ne 0)
{
return $iResult
}

$strDnsName = $objClusterResNet.PrivateProperties.DnsName
$blnUseResource = ($strTargetComputerShortName -ieq $strDnsName)

if ($blnUseResource)
{
$objResGroups = Get-CimAssociatedInstance -InputObject $objClusterResNet -Association $WMI_MSCLUSTER_RESOURCEGROUP_TO_RESOURCE

if ($error.Count -ne 0)
{
return $iResult
}

foreach ($objResGroupAsc in $objResGroups)
{
$strClusterGroupName = $objResGroupAsc.Name
break
}
}
}

$error.Clear()
}

$objResourceGroups = $null

if ($false -eq [string]::IsNullOrEmpty($strClusterGroupName) )
{
$Filter = "Name='$strClusterGroupName'"
$objResourceGroups = Get-CimInstance -Namespace $WMI_MSCLUSTER_NAMESPACE -Class $WMI_MSCLUSTER_RESOURCEGROUP -Filter $Filter -ErrorAction SilentlyContinue
}

if ($error.Count -ne 0)
{
return $iResult
}

foreach ($objResourceGroup in $objResourceGroups)
{

$objClusterResources =(Get-CimAssociatedInstance -InputObject $objResourceGroup -Association $WMI_MSCLUSTER_RESOURCEGROUP_TO_RESOURCE)
if ($error.Count -ne 0)
{
return $iResult
}

foreach ($objClusterResource in $objClusterResources)
{
#Get the associated disk
$objClusterDisks = (Get-CimAssociatedInstance -InputObject $objClusterResource -Association $WMI_CLUSTER_RESOURCE_TO_DISK_ASSOCIATOR_CLASS)
if ($error.Count -ne 0)
{
return $iResult
}

foreach ($objClusterDisk in $objClusterDisks)
{
#Get the associated disk partition
$objClusterDiskPartitions = (Get-CimAssociatedInstance -InputObject $objClusterDisk -Association $WMI_CLUSTER_DISKPARTITION_TO_DISK_ASSOCIATOR_CLASS)
if ($error.Count -ne 0)
{
return $iResult
}

foreach ($objClusterDiskPartition in $objClusterDiskPartitions)
{
$intSuc = CreateDiscoveryData $objClusterDisk $objClusterDiskPartition $objClusterResource $strTargetComputer $strClusterName $objDiscoveryData
if ($error.Count -ne 0 -or $intSuc -eq $SCRIPT_WITH_ERROR)
{
return $SCRIPT_WITH_ERROR
}

}
}
}

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

}

if($intSuc -eq $null)
{
$iResult = $SCRIPT_SUCCESS

}
else
{
$iResult = $intSuc
}

return $iResult
}

Function DiscoverClusterDisksNonCim($strTargetComputer, $strClusterName,$strClusterGroupName, $objDiscoveryData) #As Integer
{
$ErrorActionPreference = 'SilentlyContinue'
$error.Clear()
$iResult = $SCRIPT_WITH_ERROR
$oWMI = Get-WMIObject -Namespace $WMI_MSCLUSTER_NAMESPACE -Class $WMI_MSCLUSTER_CLUSTER_RESOURCE -ErrorAction SilentlyContinue | select -First 1

if ($error.Count -ne 0)
{
return $iResult
}

if ([string]::IsNullOrEmpty($strClusterGroupName))
{
$objClusterResNetworks = Get-WMIObject -Namespace $WMI_MSCLUSTER_NAMESPACE -Class $WMI_MSCLUSTER_CLUSTER_RESOURCE -Filter "Type = 'Network Name'" -ErrorAction SilentlyContinue
if ($error.Count -ne 0)
{
return $iResult
}

$strTargetComputerShortName = Get-ComputerName -strTargetComputer $strTargetComputer

foreach ($objClusterResNet in $objClusterResNetworks)
{
$strDnsName = $objClusterResNet.PrivateProperties.DnsName
$blnUseResource = ($strTargetComputerShortName -ieq $strDnsName)

if ($blnUseResource)
{
$objResGroups = $objClusterResNet.GetRelated("MSCluster_ResourceGroup")
if ($error.Count -ne 0)
{
return $iResult
}

foreach ($objResGroupAsc in $objResGroups)
{
$strClusterGroupName = $objResGroupAsc.Name
break
}
}
}

$error.Clear()
}

$Filter = "Name='$strClusterGroupName'"
$objResourceGroups = Get-WMIObject -Namespace $WMI_MSCLUSTER_NAMESPACE -Class $WMI_MSCLUSTER_RESOURCEGROUP -Filter $Filter -ErrorAction SilentlyContinue

if ($error.Count -ne 0)
{
return $iResult
}


foreach ($objResourceGroup in $objResourceGroups)
{
$objClusterResources = $objResourceGroup.GetRelated("MSCluster_Resource")
if ($error.Count -ne 0)
{
return $iResult
}
foreach ($objClusterResource in $objClusterResources)
{
#Get the associated disk
$objClusterDisks = $objClusterResource.GetRelated("MSCluster_Disk")
if ($error.Count -ne 0)
{
return $iResult
}

foreach ($objClusterDisk in $objClusterDisks)
{
#Get the associated disk partition
$objClusterDiskPartitions = $objClusterDisk.GetRelated("MSCluster_DiskPartition")
if ($error.Count -ne 0)
{
return $iResult
}

foreach ($objClusterDiskPartition in $objClusterDiskPartitions)
{
$intSuc = CreateDiscoveryData $objClusterDisk $objClusterDiskPartition $objClusterResource $strTargetComputer $strClusterName $objDiscoveryData
if ($error.Count -ne 0 -or $intSuc -eq $SCRIPT_WITH_ERROR)
{
return $SCRIPT_WITH_ERROR
}
}
}
}

if ($error.Count -ne 0)
{
return $iResult
}


}

if($intSuc -eq $null)
{
$iResult = $SCRIPT_SUCCESS

}
else
{
$iResult = $intSuc
}

return $iResult
}

#****************************************************************************************************************
# 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,$strClusterGroupName, $objDiscoveryData,$useCIM) #As Integer
{
$blnUseResource = $false

$ErrorActionPreference = 'SilentlyContinue'
#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)
{
$iResult= DiscoverClusterDisksCim -strTargetComputer $strTargetComputer -strClusterName $strClusterName -strClusterGroupName $strClusterGroupName -objDiscoveryData $objDiscoveryData
}else
{

$iResult= DiscoverClusterDisksNonCim -strTargetComputer $strTargetComputer -strClusterName $strClusterName -strClusterGroupName $strClusterGroupName -objDiscoveryData $objDiscoveryData


}

return $iResult
}

#****************************************************************************************************************
# 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($ClusterDiskClassName)

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


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

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

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

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

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

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

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


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

$objDiscoveryData.AddInstance($objCSVInstance)
if ($error.Count -ne 0)
{
return $SCRIPT_WITH_ERROR
}

return $SCRIPT_SUCCESS

}


Function Get-ScriptName()
{
return "-- Cluster Disks Discovery Script -- `n`nScript name: " + (Split-Path $MyInvocation.ScriptName -Leaf) + "`nVersion: " + $SCRIPT_VERSION + "`n"
}

Function LogScriptEvent($LogType,$EventId,$EventLevel,$Message,$objMomScriptAPI)
{
$ErrorActionPreference = 'SilentlyContinue'
$error.Clear()

$LogScriptName = Get-ScriptName
if ( 0 -eq $LogType)
{
if ($null -eq $objMomScriptAPI)
{
return
}

$objMomScriptAPI.LogScriptEvent($LogScriptName,$EventId,$EventLevel,$Message)
}
}
################################################################
##Common Functions
################################################################
$CIM_ERROR_INVALIDCLASS = 2147749902
$CIM_ERROR_INVALIDNAMESPACE = 2147749904
$WMI_ERROR_INVALIDCLASS = -2147217392
$WMI_ERROR_INVALIDNAMESPACE = -2147217394


Function Check-WmiException ($Exception)
{
$ErrorActionPreference = 'SilentlyContinue' # Scoped only to function
$error.Clear()

$bresult = $false

if ($null -eq $Exception)
{
return $bresult
}

$type = $Exception.GetType()

#Invalid ClassName or NameSpace
if([System.Management.ManagementException] -eq $type)
{
$ErrorCode = $Exception.ErrorCode.value__
if ($WMI_ERROR_INVALIDCLASS -eq $ErrorCode -or $WMI_ERROR_INVALIDNAMESPACE -eq $ErrorCode)
{
$bresult = $true
}
}

return $bresult

}

Function Check-CimException ($Exception)
{
$ErrorActionPreference = 'SilentlyContinue' # Scoped only to function
$error.Clear()

$bresult = $false

if ($null -eq $Exception)
{
return $bresult
}

$type = $Exception.GetType()
$error.Clear()
$WmiExcept = [Microsoft.Management.Infrastructure.CimException] -eq $type
if ($error.Count -ne 0)
{
$error.Clear()
return $bresult
}
#Invalid ClassName or NameSpace
if($WmiExcept)
{
$ErrorCode = $Exception.ErrorData.Error_code
if ($CIM_ERROR_INVALIDCLASS -eq $ErrorCode -or $CIM_ERROR_INVALIDNAMESPACE -eq $ErrorCode)
{
$bresult = $true
}
}

return $bresult

}

Function Convert-ToBoolean([string] $sBool)
{
[bool] $result = $false
[bool] $iresult = $false

if ($false -eq [string]::IsNullOrEmpty($sBool) )
{
$result = $sBool.Equals("true",[System.StringComparison]::InvariantCultureIgnoreCase)
$iresult = $sBool.Equals("1",[System.StringComparison]::InvariantCultureIgnoreCase)
$result = $result -or $iresult
}

return $result
}


Function CheckCimModule()
{
$ErrorActionPreference = 'SilentlyContinue' # Scoped only to function
$error.Clear()

$retval = $false
$cim = Get-Module -Name CimCmdlets

########Check for powershell 1.0
if ($error.Count -ne 0)
{
$type = $error[0].Exception.GetType()
if ([System.Management.Automation.CommandNotFoundException] -eq $type)
{
return $retval
}

$error.Clear()
}

if ($null -eq $cim)
{
Import-Module CimCmdLets
if ($error.Count -eq 0)
{
$retval = $true
}

$error.Clear()
}
else
{
$retval = $true
}

return $retval
}

function CheckCmdLets()
{
$ErrorActionPreference = 'SilentlyContinue' # Scoped only to function
$error.Clear()

$retval = $false
$objSWbemObjectSet =$null

if (CheckCimModule)
{
$objSWbemObjectSet = Get-CimInstance -Class Win32_OperatingSystem -ErrorAction Stop
if ($error.Count -eq 0)
{
$retval = $true
}
}

$error.Clear()
return $retval;
}

Function Get-ClusterNameFromRegistry
{
$ErrorActionPreference = 'SilentlyContinue' # Scoped only to function
$error.Clear()
$ClusterPath = "HKLM:\Cluster"
$key = Get-ItemProperty -Path $ClusterPath -Name "ClusterName"
$result = [string]::Empty

if ($key -ne $null)
{
$result = $key.ClusterName
}

$error.Clear()
return $result

}

Function Get-ClusterName ($useCim)
{
$ClusterName = Get-ClusterNameFromRegistry

If (-Not [string]::IsNullOrEmpty($ClusterName) )
{
return $ClusterName
}

$ErrorActionPreference = 'SilentlyContinue' # Scoped only to function
$error.Clear()
$WMI_MSCLUSTER_NAMESPACE_Local = "root\MSCluster"

if($useCIM)
{
$Clusters = Get-CimInstance -ClassName MSCluster_Cluster -NameSpace $WMI_MSCLUSTER_NAMESPACE_Local
if ($error.Count -ne 0)
{
return $ClusterName
}

foreach ($Cluster in $Clusters)
{
$ClusterName = $Cluster.Name
break
}
}else
{
$Clusters = Get-WmiObject -Class MSCluster_Cluster -NameSpace $WMI_MSCLUSTER_NAMESPACE_Local
if ($error.Count -ne 0)
{
return $ClusterName
}

foreach ($Cluster in $Clusters)
{
$ClusterName = $Cluster.Name
break
}
}

$error.Clear()

return $ClusterName

}


Function Get-ComputerName([string]$strTargetComputer)
{
$ErrorActionPreference = 'SilentlyContinue' # Scoped only to function
$error.Clear()
$strTargetComputerShortName = $strTargetComputer

if([string]::IsNullOrEmpty($strTargetComputerShortName))
{
return [string]::Empty
}

$index = $strTargetComputer.IndexOf(".")

if ( $index -gt 0)
{
$strTargetComputerShortName = $strTargetComputer.Substring(0, $index)
}

return $strTargetComputerShortName
}



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="PsProbe">
<Node ID="DS"/>
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Discovery.Data</OutputType>
</DataSourceModuleType>