执行群集节点方法

Microsoft.Windows.Cluster.Node.Action (WriteActionModuleType)

此写入操作在群集节点中执行操作。

Element properties:

TypeWriteActionModuleType
IsolationAny
AccessibilityInternal
RunAsMicrosoft.Windows.Cluster.PrivilegedAccount
InputTypeSystem.BaseData

Member Modules:

ID Module Type TypeId RunAs 
WA WriteAction Microsoft.Windows.PowerShellWriteAction Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
TimeoutSecondsint$Config/TimeoutSeconds$超时(秒)

Source Code:

<WriteActionModuleType ID="Microsoft.Windows.Cluster.Node.Action" Accessibility="Internal" RunAs="Cluster!Microsoft.Windows.Cluster.PrivilegedAccount" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="MethodName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TimeoutSeconds" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<WriteAction ID="WA" TypeID="Windows!Microsoft.Windows.PowerShellWriteAction">
<ScriptName>ClusterNodeExecuteMethod.ps1</ScriptName>
<ScriptBody><Script>param($strComputer,$MethodName)
#Copyright (c) Microsoft Corporation. All rights reserved.
# Process Arguments:
# 0 - Node
# 1 - MethodName

$Trace = $false;


function HasMethod($className, $methodName)
{
$methods = $null;
$objSvc = $null;
try {
if($Is_OS_More_Than_2012)
{
try{
$methods = (Get-CimClass -ClassName $className -ComputerName $strComputer -NameSpace "root\mscluster" -ErrorAction Stop).CimClassMethods[$methodName]
}catch{
import-module cimcmdlets
$methods = (Get-CimClass -ClassName $className -ComputerName $strComputer -NameSpace "root\mscluster").CimClassMethods[$methodName]
}
}else{
$objSvc = Get-WmiObject -ComputerName $strComputer -NameSpace "root\mscluster" -Query "select * from $className"
$methods = $objSvc | get-member | select-string -pattern "$methodName"
}
}
catch {
}

if ($methods -eq $null) {
PrintTrace("There is no method " + $methodName + " in class " + $className);
return $false;
}

PrintTrace("Method " + $methodName + " in class " + $className + " was found!");
return $true;
}

function PrintTrace($msg) {
if ($Trace) {
Write-Host($msg);
}
}

function PrintError($error)
{
if ($Trace)
{
Write-Host("============================= BEGIN SCRIPT ERROR =================================\n");
Write-Host("Error Number : " + $error.number);
Write-Host("Error Code : " + ($error.number + 0xFFFF));
#Write-Host("Win32 Facility : " + ($error.number -shr 16 -band 0x1FFF));
Write-Host("Error Description : " + $error.description + "\n");
Write-Host("============================== END SCRIPT ERROR ==================================\n");
}
}

function CheckByOSCurrentVersion() #As Boolean
{
$strCurrentOSVer = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\"
$strCurrentOSVer = $strCurrentOSVer.CurrentVersion
if($strCurrentOSVer -ge $WIN_OS_2012_Ver)
{
return $true;
}
return $false;
}

$WIN_OS_2012_Ver = "6.2"
$Is_OS_More_Than_2012 = CheckByOSCurrentVersion

try {
# there is difference between 2003 and 2008
# check if object has method to pause/resume node

$objSvc = $null;

if(HasMethod "MSCluster_Service" $MethodName)
{
if($Is_OS_More_Than_2012)
{
try{
$objSvc = Get-CimInstance -ComputerName $strComputer -NameSpace "root\mscluster" -Query "select * from MSCluster_Service where Name= ""Cluster Service"" AND SystemName= ""$strComputer""" -ErrorAction Stop
}catch{
import-module cimcmdlets
$objSvc = Get-CimInstance -ComputerName $strComputer -NameSpace "root\mscluster" -Query "select * from MSCluster_Service where Name= ""Cluster Service"" AND SystemName= ""$strComputer"""
}
}else{
$objSvc = Get-WmiObject -ComputerName $strComputer -NameSpace "root\mscluster" -Query "select * from MSCluster_Service where Name= ""Cluster Service"" AND SystemName= ""$strComputer"""
}
}
elseif(HasMethod "MSCluster_Node" $MethodName)
{
if($Is_OS_More_Than_2012)
{
try{
$objSvc = Get-CimInstance -ComputerName $strComputer -NameSpace "root\mscluster" -Query "select * from MSCluster_Node where Name=""$strComputer""" -ErrorAction Stop
}catch{
import-module cimcmdlets
$objSvc = Get-CimInstance -ComputerName $strComputer -NameSpace "root\mscluster" -Query "select * from MSCluster_Node where Name=""$strComputer"""
}
}else{
$objSvc = Get-WmiObject -ComputerName $strComputer -NameSpace "root\mscluster" -Query "select * from MSCluster_Node where Name=""$strComputer"""
}
}
if ($objSvc -ne $null)
{

PrintTrace("EXECUTING METHOD " + $MethodName);
# Execute the method and retrieve the value
if($Is_OS_More_Than_2012)
{
invoke-CimMethod -InputObject $objSvc -MethodName $MethodName
}else{
$objOutParam = $objSvc.$MethodName.Invoke();
}
}
}
catch{
Write-Error $Error.description;
}

</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>strComputer</Name>
<Value>$Target/Property[Type='ClusLibrary!Microsoft.Windows.Cluster.Node']/NodeName$</Value>
</Parameter>
<Parameter>
<Name>MethodName</Name>
<Value>$Config/MethodName$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
<StrictErrorHandling>true</StrictErrorHandling>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="WA"/>
</Composition>
</Composite>
</ModuleImplementation>
<InputType>System!System.BaseData</InputType>
</WriteActionModuleType>