Individua l'origine dati di script del nome cluster

Microsoft.Windows.Server.ClusterSharedVolumeMonitoring.VirtualServer.DiscoverClusterName.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:

IDParameterTypeSelectorDisplay NameDescription
IntervalSecondsint$Config/IntervalSeconds$Intervallo
LogSuccessEventbool$Config/LogSuccessEvent$Registra evento di successo
ScriptGroupIdstring$Config/ScriptGroupId$Origine del registro eventi
TimeoutSecondsint$Config/TimeoutSeconds$Timeout

Source Code:

<DataSourceModuleType ID="Microsoft.Windows.Server.ClusterSharedVolumeMonitoring.VirtualServer.DiscoverClusterName.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="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.CSV.DiscoverClusterName.ps1</ScriptName>
<ScriptBody><Script>

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

$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"

#WMI constants
$CIMV2_WMI_NAMESPACE = "root\cimv2"
$WMI_MSCLUSTER_NAMESPACE = "root\MSCluster"
$WMI_MSCLUSTER_CLUSTER_CLASS = "MSCluster_Cluster"

$WIN_SRV_2008_BUILD_NUMBER = 6000

#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.

$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
#$mobjDebugLog #As TextStream
#$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, gets the cluster name and
# discovers the containment relationship between a cluster and
# the targeted cluster virtual server.
# PARAMETERS: void
#*********************************************************************************************
Function Main()
{
$objMomScriptAPI = New-Object -comObject MOM.ScriptAPI

#Create new discovery data object
$objDiscoveryData = $objMomScriptAPI.CreateDiscoveryData(0, $strSourceID, $strManagedEntityId)

#DiscoverRelationship
if (CheckOSBuildNumber $WIN_SRV_2008_BUILD_NUMBER)
{
$blnSuccess = DiscoverClusterName $strTargetComputer $objDiscoveryData
}
else
{
$blnSuccess = $true
}

if ($blnSuccess)
{
if ([System.Convert]::ToBoolean($mblnLogSuccessEvent) -eq $true)
{
$objMomScriptAPI.LogScriptEvent(("-- Cluster Shared Volumes Cluster Discovery Script -- `n`nScript name: " + (Split-Path $MyInvocation.ScriptName -Leaf) + "`nVersion: " + $SCRIPT_VERSION + "`n"),
$EVENT_ID_SUCCESS, $EVENT_TYPE_INFORMATION, "`nScript executed successfully.")
}
}
else
{
$objMomScriptAPI.LogScriptEvent(("-- Cluster Shared Volumes Cluster Discovery Script -- `n`nScript name: " + (Split-Path $MyInvocation.ScriptName -Leaf) + "`nVersion: " + $SCRIPT_VERSION + "`n"),
$EVENT_ID_SCRIPTERROR, $EVENT_TYPE_WARNING, "`nAn error occurred while running script")
}

#Return discovery data
if ($blnSuccess)
{
$objDiscoveryData
}
}

#****************************************************************************************************************
# FUNCTION: DiscoverClusterName
# DESCRIPTION: Discover instances of the relationship class
# #Microsoft.Windows.Server.ClusterSharedVolumeMonitoring.Microsoft.Windows.Cluster.Contains.Microsoft.Windows.Cluster.VirtualServer#.
# PARAMETERS: IN String strTargetComputer: principal name of the targeted #Microsoft.Windows.Cluster.VirtualServer# instance.
# OUT Object objDiscoveryData: initialised DiscoveryData instance
# RETURNS: Boolean: True if successful
#****************************************************************************************************************
Function DiscoverClusterName([string]$strTargetComputer, $objDiscoveryData) #As Boolean
{
#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
}

#Retrieve the cluster name from WMI and
#discover the relationship
$strClusterName = GetClusterName
if ($strClusterName.Length -gt 0)
{
#Create the cluster name instance
$objClusterNameInstance = $objDiscoveryData.CreateClassInstance("$MPElement[Name='Microsoft.Windows.Server.ClusterSharedVolumeMonitoring.Cluster']$")
#Add key property (is hosted on Microsoft.Windows.Cluster.VirtualServer
$objClusterNameInstance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $strTargetComputer)
#Property ClusterName
$objClusterNameInstance.AddProperty("$MPElement[Name='Microsoft.Windows.Server.ClusterSharedVolumeMonitoring.Cluster']/ClusterName$", $strClusterName)

#add the instance to the discovery data
$objDiscoveryData.AddInstance($objClusterNameInstance)

return $true
}
else
{
return $false
}
}

#****************************************************************************************************************
# FUNCTION: GetClusterName
# DESCRIPTION: Returns the cluster name of the given cluster virtual name
# RETURNS: String strClusterName: string to return the cluster name
#****************************************************************************************************************
Function GetClusterName() #As Boolean
{
$strClusterName = ""

#Connect to WMI NS \\.\root\MSCluster
$strWQLQuery = "select * from " + $WMI_MSCLUSTER_CLUSTER_CLASS
if($useCIM){
$objClusters = Get-CimInstance -Namespace $WMI_MSCLUSTER_NAMESPACE -Query $strWQLQuery -ErrorAction SilentlyContinue
}else{
$objClusters = Get-WMIObject -Namespace $WMI_MSCLUSTER_NAMESPACE -Query $strWQLQuery -ErrorAction SilentlyContinue
}
if ($objClusters -ne $null)
{
foreach ($objCluster in $objClusters)
{
$strClusterName = $objCluster.Name
}
}

return $strClusterName
}

#******************************************************************************
# FUNCTION: CheckOSBuildNumber
# DESCRIPTION: Returns True if the property BuildNumber from the Win32_OperatingSystem
# instance is greater or equal the given build number using the CIMv2 WMI namespace.
# PARAMETERS: IN Long lngBuildNumber: build number to check
# RETURNS: Boolean: True, if build is greater or equal than the given number
#******************************************************************************
Function CheckOSBuildNumber($lngBuildNumber) #As Boolean
{
#Get the computersystem instance
if($useCIM){
$objSWbemObjectSet = Get-Ciminstance -Query "select * from Win32_OperatingSystem" -ErrorAction SilentlyContinue
}else{
$objSWbemObjectSet = Get-WMIObject -Query "select * from Win32_OperatingSystem" -ErrorAction SilentlyContinue
}
foreach ($objSWbemObject in $objSWbemObjectSet)
{
if (($objSWbemObject.BuildNumber -as [int]) -ge $lngBuildNumber)
{
return $true
}
}

return $false
}

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>
</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>