Control cluster from command line write action

Microsoft.Windows.Cluster.ControlClusterFromCommandLine (WriteActionModuleType)

This write action executes commands that controls windows cluster.

Element properties:

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

Member Modules:

ID Module Type TypeId RunAs 
WA WriteAction System.CommandExecuter Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
TimeoutSecondsint$Config/TimeoutSeconds$Timeout(sec)

Source Code:

<WriteActionModuleType ID="Microsoft.Windows.Cluster.ControlClusterFromCommandLine" Accessibility="Internal" RunAs="Cluster!Microsoft.Windows.Cluster.PrivilegedAccount" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="Operation" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="TimeoutSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="0" name="ResourceType" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="0" name="ResourceName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="0" name="Command" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<WriteAction ID="WA" TypeID="System!System.CommandExecuter">
<ApplicationName>%SystemRoot%\system32\cmd.exe</ApplicationName>
<WorkingDirectory/>
<CommandLine>/c $file/Main.cmd$</CommandLine>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
<RequireOutput>true</RequireOutput>
<Files>
<File>
<Name>Main.cmd</Name>
<Contents><Script>

@echo off
set clcmd=%windir%\system32\cluster.exe
if Exist "%clcmd%" (
"%clcmd%" $Config/Operation$
goto end
)

set psscript=Cluster.ps1
set vbscript=Cluster.js
set cscript=%windir%\system32\cscript.exe
set ps=%windir%\system32\WindowsPowerShell\v1.0\powershell.exe
set params=

if Exist "%cscript%" goto vb
if Exist "%ps%" goto pshell
goto end
:vb
if not exist "%~dp0%vbscript%" goto end

"%cscript%" /nologo "%~dp0%vbscript%"
goto end
:pshell
if not exist "%~dp0%psscript%" goto end

"%ps%" -nologo -EP bypass -command "&amp; '%~dp0%psscript%'"
goto end

:end



</Script></Contents>
<Unicode>false</Unicode>
</File>
<File>
<Name>Cluster.ps1</Name>
<Contents><Script>

function Get-CmdFilename([string]$fullname)
{
$ErrorActionPreference = 'SilentlyContinue' # Scoped only to function
$error.Clear()

$fileparam = "psparams.txt"
$fullnameparams = ".\$fileparam"
$fullparams = [System.IO.Path]::GetFullPath($fullnameparams)
if (0 -ne $error.Count)
{
$error.Clear()
$fullparams = $fullnameparams
}

if ($false -eq [string]::IsNullOrEmpty($fullname))
{
$error.Clear()
$fullnameparams = [System.IO.Path]::GetDirectoryName($fullname)
if (0 -eq $error.Count)
{
$fullpath = [System.IO.Path]::Combine($fullnameparams,$fileparam)
if (0 -ne $error.Count)
{
$error.Clear()
$fullpath = $fullnameparams + "\" + $fileparam
}

$fullparams = $fullpath
}
}

$error.Clear()
$IsFlag = $null
$IsFlag = [System.IO.File]::Exists($fullparams)

if ($null -eq $IsFlag)
{
$error.Clear()
return $null
}

if ($false -eq $IsFlag )
{
$fullparams = $null
}

$error.Clear()

return $fullparams
}

Function Parse-Params([string]$Value)
{
$ErrorActionPreference = 'SilentlyContinue' # Scoped only to function
$error.Clear()

if ([string]::IsNullOrEmpty($Value))
{
return null
}

$i = $Value.IndexOf("=")
if (-1 -eq $i) { return $null; }

$i++;

$result = ""

if ($i -le $Value.Length )
{
$result = $Value.Substring($i)
}

return $result
}

Function Get-CmdParams([string]$fullname,[int]$MaxCount=0)
{
$ErrorActionPreference = 'SilentlyContinue' # Scoped only to function
$error.Clear()

if ($MaxCount -lt 0)
{
$MaxCount = 0
}

$filename = Get-CmdFilename -fullname $fullname

if ($null -eq $filename)
{
return $null
}

$ap = Get-Content -Path $filename -Force

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

if (0 -eq $ap.Length)
{
return $null
}

$result = @()
$i = 0
foreach($d in $ap)
{
$p = Parse-Params -Value $d
if ($null -ne $p)
{
$i++
if ($i -gt $MaxCount -and 0 -ne $MaxCount) { break; }
$result += $p
}
}

return $result
}

function Check-WmiMethod($oObject,[string]$MethodName,$useCim) #As Boolean
{
$ErrorActionPreference = 'SilentlyContinue' # Scoped only to function
$error.Clear()

$method = $null

if ([string]::IsNullOrEmpty($oObject))
{
return $NodeName
}


if($true -eq $useCim)
{
$method = $oObject | Get-Member -Name $MethodName -MemberType Method
}
else
{
$methods = $oObject.CimClass.CimClassMethods
if($null -ne $methods)
{
$method = $methods[$MethodName]
}
}

$result = ($null -ne $method -and 0 -eq $error.Count )

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)
{
if ($null -eq $error[0].Exception)
{
return $retval
}

$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)
{
Load-CimModules
try
{
$cimSessionOption = New-CimSessionOption -Protocol DCOM
$cimsession = New-CimSession -SessionOption $cimSessionOption
$objSWbemObjectSet = Get-CimInstance -CimSession $cimsession -Class Win32_OperatingSystem
}
catch
{
$objSWbemObjectSet = Get-WMIObject -Class Win32_OperatingSystem
}
Finally
{
Get-CimSession | Remove-CimSession
$cimsession =$null
$cimSessionOption = $null
}
if ($error.Count -eq 0)
{
$retval = $true
}
}

$error.Clear()
return $retval;
}

function Check-CimInstance($oWmiInstance)
{
$result = $null

if([string]::IsNullOrEmpty($oWmiInstance))
{
return $result
}

$type = $oWmiInstance.GetType()
if([string]::IsNullOrEmpty($type))
{
return $result
}

$useCim = $type.Fullname -eq "Microsoft.Management.Infrastructure.CimInstance"
if ($true -eq $useCim)
{
return $useCim
}

$useCim = $type.Fullname -eq "System.Management.ManagementObject"
if ($true -eq $useCim)
{
$result = $false
}

return $result
}

Function Get-WmiEscapedName([string]$Name)
{
$Name = ($Name -replace "\\", "\\") -replace "'","\'"

return $Name
}

Function Get-WmiCimSession([string]$ComputerName)
{
$ErrorActionPreference = 'SilentlyContinue'
$Error.Clear()

$CimSession = = $null
$CimSession = = Get-CimSession -ComputerName $ComputerName

if ($null -eq $CimSession)
{
$Error.Clear()
$CimSession = New-CimSession -ComputerName $ComputerName
}
else
{
if ($CimSession.Count -gt 1)
{
$CimSession = $cims[0]
}

}

return $CimSession
}

Function Get-WmiCimAssociatorInstance
{
param (
[string]$ComputerName,
[string]$sNamespace,
[string]$sAssociatorName,
$oWmiInstance,
[string]$relatedClass,
[string]$Source,
[string]$Target,
$CimSession
)

$ErrorActionPreference = 'SilentlyContinue'
$Error.Clear()

$result = $null

if ([string]::IsNullOrEmpty($CimSession))
{
$cimSessionOption = New-CimSessionOption -Protocol DCOM
$cimsession = New-CimSession -ComputerName $ComputerName -SessionOption $cimSessionOption
}
else
{
$type = $CimSession.GetType()
if ([string]::IsNullOrEmpty($type))
{
return $result
}

if ("Microsoft.Management.Infrastructure.CimSession" -ne $type.FullName)
{
$cimSessionOption = New-CimSessionOption -Protocol DCOM
$cimsession = New-CimSession -ComputerName $ComputerName -SessionOption $cimSessionOption
}

}

if (0 -ne $Error.Count)
{
return $result
}
$result = $CimSession.EnumerateAssociatedInstances($sNamespace,$oWmiInstance,$sAssociatorName,$relatedClass,$Source,$Target)

return $result
}

Function Get-WmiAssociatorInstanceNoAbort
{
param (
[string]$ComputerName,
[string]$sNamespace,
[string]$sAssociatorName,
$oWmiInstance,
[string]$relatedClass,
[string]$Source,
[string]$Target,
$CimSession
)

$ErrorActionPreference = 'SilentlyContinue'
if ([string]::IsNullOrEmpty($ComputerName))
{
$ComputerName = "."
}

$Error.Clear()

$oInstance = $null
$result = @()

if([string]::IsNullOrEmpty($oWmiInstance))
{
return $result
}

$useCim = Check-CimInstance -oWmiInstance $oWmiInstance

if ($null -eq $useCim)
{
return $result
}

if ($true -eq $useCim)
{
$oInstance = Get-WmiCimAssociatorInstance -ComputerName $ComputerName -sNamespace $sNamespace -sAssociatorName $sAssociatorName -oWmiInstance $oWmiInstance -Source $Source -Target $Target -CimSession $CimSession
}
else
{
$oInstance = $oWmiInstance.GetRelated($relatedClass,$sAssociatorName,$null,$null,$Target,$Source,$null,$null)
}

if ($null -eq $oInstance)
{

return $null
}

$result += $oInstance

return $result
}

Function Get-WmiInstanceNoAbort
{
param (
[string]$ComputerName,
[string]$sNamespace,
[string]$sClassName,
[string]$sFilter,
[bool] $useCim
)

$ErrorActionPreference = 'SilentlyContinue'
$error.Clear()

$KerberosErrorCode = 2147943712
$ConnectionErrorCode = 2147942453
$WmiConnectErrorCode = -2147023174

if ([string]::IsNullOrEmpty($ComputerName))
{
$ComputerName = "."
}

if ([string]::IsNullOrEmpty($sNamespace))
{
$sNamespace = "root\cimv2"
}

if ($true -eq $useCim)
{
$oInstance = $null
if ([string]::IsNullOrEmpty($sFilter))
{
Load-CimModules
try
{
$cimSessionOption = New-CimSessionOption -Protocol DCOM
$cimsession = New-CimSession -ComputerName $ComputerName -SessionOption $cimSessionOption
$oInstance = Get-CimInstance -CimSession $cimsession -Namespace $sNamespace -ClassName $sClassName
}
catch
{
$oInstance = Get-WMIObject -Namespace $sNamespace -ClassName $sClassName -ComputerName $ComputerName
}
Finally
{
Get-CimSession | Remove-CimSession
$cimsession =$null
$cimSessionOption = $null
}
if ($error.Count -ne 0)
{
$ErrorCode = $error[0].Exception.ErrorData.Error_code
If ($KerberosErrorCode -eq $ErrorCode -or $ConnectionErrorCode -eq $ErrorCode)
{
$error.Clear()
Load-CimModules
try
{
$cimSessionOption = New-CimSessionOption -Protocol DCOM
$cimsession = New-CimSession -SessionOption $cimSessionOption
$oInstance = Get-CimInstance -CimSession $cimsession -Namespace $sNamespace -ClassName $sClassName
}
catch
{
$oInstance = Get-WMIObject -Namespace $sNamespace -ClassName $sClassName
}
Finally
{
Get-CimSession | Remove-CimSession
$cimsession =$null
$cimSessionOption = $null
}
}
}
}
else
{
Load-CimModules
try
{
$cimSessionOption = New-CimSessionOption -Protocol DCOM
$cimsession = New-CimSession -ComputerName $ComputerName -SessionOption $cimSessionOption
$oInstance = Get-CimInstance -CimSession $cimsession -Namespace $sNamespace -ClassName $sClassName -Filter $sFilter
}
catch
{
$oInstance = Get-WMIObject -Namespace $sNamespace -ClassName $sClassName -ComputerName $ComputerName -Filter $sFilter
}
Finally
{
Get-CimSession | Remove-CimSession
$cimsession =$null
$cimSessionOption = $null
}
if ($error.Count -ne 0)
{
$ErrorCode = $error[0].Exception.ErrorData.Error_code
If ($KerberosErrorCode -eq $ErrorCode -or $ConnectionErrorCode -eq $ErrorCode)
{
$error.Clear()
Load-CimModules
try
{
$cimSessionOption = New-CimSessionOption -Protocol DCOM
$cimsession = New-CimSession -SessionOption $cimSessionOption
$oInstance = Get-CimInstance -CimSession $cimsession -Namespace $sNamespace -ClassName $sClassName -Filter $sFilter
}
catch
{
$oInstance = Get-WMIObject -Namespace $sNamespace -ClassName $sClassName -Filter $sFilter
}
Finally
{
Get-CimSession | Remove-CimSession
$cimsession =$null
$cimSessionOption = $null
}
}
}

}
}
else
{
$oInstance = $null
if ([string]::IsNullOrEmpty($sFilter))
{
$oInstance = Get-WmiObject -Class $sClassName -Namespace $sNamespace -ComputerName $ComputerName
if ($error.Count -ne 0)
{
$ErrorCode = $error[0].Exception.ErrorCode
If ($WmiConnectErrorCode -eq $ErrorCode)
{
$error.Clear()
$oInstance = Get-WmiObject -Class $sClassName -Namespace $sNamespace
}
}
}
else
{
$oInstance = Get-WmiObject -Class $sClassName -Namespace $sNamespace -Filter $sFilter -ComputerName $ComputerName
if ($error.Count -ne 0)
{
$ErrorCode = $error[0].Exception.ErrorCode
If ($WmiConnectErrorCode -eq $ErrorCode)
{
$error.Clear()
$oInstance = Get-WmiObject -Class $sClassName -Namespace $sNamespace -Filter $sFilter
}
}

}
}

return $oInstance
}

Function ConvertNumericResourceStateToString($state)
{
if ($null -eq $state)
{
return "Unknown"
}

$States = @{[uint32]0 = "Inherited";[uint32]1 = "Initializing";[uint32]2 = "Online";[uint32]3 = "Offline";[uint32]4 = "Failed";[uint32]128 = "Pending";[uint32]129 = " Online Pending";[uint32]130 = "Offline Pending"}
$textualState = $States[$state]

if ($null -eq $textualState)
{
$textualState = "Unknown"
}

return $textualState;
}

Function ConvertNumericResourceGroupStateToString($state)
{
if ($null -eq $state)
{
return "Unknown"
}

$States = @{[uint32]0 = "Online";[uint32]1 = "Offline";[uint32]2 = "Failed";[uint32]3 = "Partially Online";[uint32]4 = "Pending"}
$textualState = $States[$state]

if ($null -eq $textualState)
{
$textualState = "Unknown"
}

return $textualState;
}


Function Load-CimModules
{
$ErrorActionPreference = 'SilentlyContinue'
$error.Clear()

$CimModule = Get-Module CimCmdlets

if ($null -eq $CimModule)
{
Import-Module CimCmdlets
$error.Clear()

}
}


#==========================================================================
# FUNCTIONS
#==========================================================================
function Main()
{
$ErrorActionPreference = 'SilentlyContinue'
$error.Clear()

$useCim = CheckCmdLets
if ($null -eq $useCim)
{
Write-Host "Cannot get wmi cmdlets version."
return
}

if ([string]::IsNullOrEmpty($ResourceName))
{
Write-Host "Resource Name is empty"
return
}

$oResource = Get-FcsResource -ResourceName $ResourceName -useCim $useCim

if(0 -ne $error.Count)
{
$e = $error[0].Exception.Message
Write-Host "Cluster resource [$ResourceName] is not found."
Write-Host "The Query returned an invalid result set. Error: $e"
return
}

if ($null -eq $oResource)
{
Write-Host "Cluster resource [$ResourceName] is not found."
return;
}

switch($MethodName)
{

"/listdep"{
Get-ClusterResDeps -oResource $oResource
break;
}
"/prop"{
$oResource | Format-List -Property *
break;
}
"/Online" {
Bring-Online -oResource $oResource -Offline $false -timeoutInSeconds $timeoutInSeconds
break;
}
"/Offline"{
Bring-Online -oResource $oResource -Offline $true -timeoutInSeconds $timeoutInSeconds
break;
}
"/status"{
Print-ResStatus -oResource $oResource -useCim $useCim
break;
}
default{
write-host "[Error]: " "Unrecognized method " $MethodName " used"
}

}

}

Function Get-FcsResource([string]$ResourceName,$useCim)
{
$ErrorActionPreference = 'SilentlyContinue'
$error.Clear()

$NameSpace = "root\mscluster"
$ClassName = "MSCluster_Resource"
$EscapeName = Get-WmiEscapedName -Name $ResourceName
$Filter = "Name='$EscapeName'"
$oResource = $null

$oResource = Get-WmiInstanceNoAbort -ComputerName $NodeName -sNamespace $NameSpace -sClassName $ClassName -sFilter $Filter -useCim $useCim

if ($oResource.Count -gt 1 )
{
$oResource = $oResource[0]
}

return $oResource
}

Function Get-ClusterResourceGroup($Resource)
{
$ErrorActionPreference = 'SilentlyContinue'
$error.Clear()

if ($false -eq [string]::IsNullOrEmpty($Resource.OwnerGroup)) {return $Resource.OwnerGroup;}

$NameSpace = "root\mscluster"
$Assoc = "MSCluster_ResourceGroupToResource"
$oGroup = $null

$oGroup = Get-WmiAssociatorInstanceNoAbort -sNamespace $NameSpace -sAssociatorName $Assoc -relatedClass "MSCluster_ResourceGroup" -oWmiInstance $Resource
$GroupName = [string]::Empty

foreach ($Group in $oGroup)
{
$GroupName = $Group.Name
break
}

$error.Clear()

return $GroupName
}

Function Get-ClusterResourceNode($Resource)
{
$ErrorActionPreference = 'SilentlyContinue'
$error.Clear()

if ($false -eq [string]::IsNullOrEmpty($Resource.OwnerNode)) {return $Resource.OwnerNode;}

$NameSpace = "root\mscluster"
$Assoc = "MSCluster_NodeToActiveResource"
$oNode = $null

if ($null -eq $Resource)
{
return $oNode
}

$oNode = Get-WmiAssociatorInstanceNoAbort -sNamespace $NameSpace -sAssociatorName $Assoc -relatedClass "MSCluster_Node" -oWmiInstance $Resource
$NodeName = [string]::Empty

foreach ($Node in $oNode)
{
$NodeName = $Node.Name
break
}

$error.Clear()

return $NodeName
}

Function Get-ClusterResDep($Resource)
{
$ErrorActionPreference = 'SilentlyContinue'
$error.Clear()

$NameSpace = "root\mscluster"
$Assoc = "MSCluster_ResourceToDependentResource"
$oNode = $null

if ($null -eq $Resource)
{
return $oNode
}

$oNode = Get-WmiAssociatorInstanceNoAbort -sNamespace $NameSpace -sAssociatorName $Assoc -relatedClass "MSCluster_Resource" -oWmiInstance $Resource -Source "Antecedent"

return $oNode
}

function Print-ResDepHeader($oResource)
{
$ErrorActionPreference = 'SilentlyContinue'
$error.Clear()

$m = Check-WmiMethod -oObject $oResource -MethodName "GetDependencies"

if ($true -eq $m)
{
$useCim = Check-CimInstance $oResource

if ($null -eq $useCim)
{
return
}

Write-Host ""
Write-Host " Listing resource dependency expression for '$($oResource.Name)':"
Write-Host " ---------------------------------------------------------------------"
if ($true -eq $useCim)
{
try
{
$cimSessionOption = New-CimSessionOption -Protocol DCOM
$cimsession = New-CimSession -SessionOption $cimSessionOption
$dep = invoke-CimMethod -CimSession $cimsession -InputObject $oResource -MethodName "GetDependencies"
}
Finally
{
Get-CimSession | Remove-CimSession
$cimsession =$null
$cimSessionOption = $null
}
}
else
{
$dep = Invoke-WmiMethod -InputObject $oResource -Name "GetDependencies"
}

Write-Host " $($dep.Expression)"
Write-Host ""
}

}

function Print-ResDeps($oResource)
{
$ErrorActionPreference = 'SilentlyContinue'
$error.Clear()

$rr = Get-ClusterResDep -Resource $oResource
if ($null -eq $rr) {return;}

$GroupName = Get-ClusterResourceGroup -Resource $oResource

foreach ($res in $rr)
{
$Node = Get-ClusterResourceNode -Resource $res
$State = ConvertNumericResourceStateToString -state $res.State

Write-Host " Resource Name: $($res.Name)"
Write-Host " Group Name : $GroupName"
Write-Host " Owner Node : $Node"
Write-Host " Status : $State"
Write-Host " "

}

Write-Host " "

}

function Print-ResStatus($oResource,$useCim)
{
$ErrorActionPreference = 'SilentlyContinue'
$error.Clear()

if ($null -eq $oResource)
{
return
}

Write-Host " "

Write-Host " Listing status for resource [$($oResource.Name)]:"
Write-Host " "

$GroupName = Get-ClusterResourceGroup -Resource $oResource
$State = ConvertNumericResourceStateToString -state $oResource.State
$Node = Get-ClusterResourceNode -Resource $oResource

Write-Host " Resource Name: [$($oResource.Name)]"
Write-Host " Owner Node : $Node"
Write-Host " Status : $State"
Write-Host " "

}

Function Bring-Online($oResource,$Offline,$timeoutInSeconds)
{
$ErrorActionPreference = 'SilentlyContinue'
$error.Clear()


$ResourceState = ConvertNumericResourceStateToString $oResource.State
Write-Host "The state of the resource [$($oResource.Name)] is $ResourceState"

If ($true -eq $Offline)
{
$state = 3
$StrState = "offline"
$method = "TakeOffline"
}
else
{
$state = 2
$StrState = "online"
$method = "BringOnline"

}

if( $state -eq $oResource.State)
{
Write-Host "The state of the resource [$($oResource.Name)] is already $StrState."
return
}

if ([string]::IsNullOrEmpty($timeoutInSeconds))
{
$timeoutInSeconds = $DefaultTimeOut
}
else
{
$error.Clear()
$timeoutInSeconds = [int32]$timeoutInSeconds
if(0 -ne $error.Count)
{
$timeoutInSeconds = $DefaultTimeOut
$error.Clear()
}
}

$useCim = Check-CimInstance -oWmiInstance $oResource

Write-Host "Attempting to bring the resource $StrState"
if($true -eq $useCim)
{
try
{
$cimSessionOption = New-CimSessionOption -Protocol DCOM
$cimsession = New-CimSession -SessionOption $cimSessionOption
$result = invoke-CimMethod -CimSession $cimsession -InputObject $oResource -MethodName $method &#x2013;Arguments @{ TimeOut = $timeoutInSeconds }
}
Finally
{
Get-CimSession | Remove-CimSession
$cimsession =$null
$cimSessionOption = $null
}
}
elseif($false -eq $useCim)
{

if ($true -eq $Offline)
{
$oResource.TakeOffline($timeoutInSeconds)
}
else
{
$oResource.BringOnline($timeoutInSeconds)
}
}
else
{
write-host "[Error]: Wrong wmi object provided. "
return

}

if (0 -ne $error.Count)
{
$message = "[Error]: Cannot bring [$($oResource.Name)] $StrState. Details: " + $error[0].Exception.Message
write-host $message
return
}
else
{
write-host "Operation completed successfully."
Write-Host "Trying to get resource state."
}

$Resource = $null
$Resource = Get-FcsResource -ResourceName $($oResource.Name) -useCim $useCim

if (0 -ne $error.Count -and $null -eq $Resource)
{
$message = "[Error]: Cannot get state of resource $($oResource.Name). Details: " + $error[0].Exception.Message
write-host $message
return
}

$ResourceState = ConvertNumericResourceStateToString -state $Resource.State
Write-Host "The state of the resource [$($oResource.Name)] is $ResourceState"

}

function Get-ClusterResDeps($oResource)
{
$ErrorActionPreference = 'SilentlyContinue'
$error.Clear()

Print-ResDepHeader -oResource $oResource
Print-ResDeps -oResource $oResource
}

Function Get-ScriptParams([string]$fullscriptname, [ref]$ResourceName, [ref]$MethodName, [ref]$timeoutInSeconds)
{
$ErrorActionPreference = 'SilentlyContinue' # Scoped only to function
$error.Clear()

$params = Get-CmdParams -fullname $fullscriptname -MaxCount 4

if ($null -eq $params -or 0 -eq $params.Count)
{
return
}

if ($null -eq $params.Count -or 1 -eq $params.Count)
{
return
}

if ($params.Count -gt 1 )
{

if ($null -ne $ResourceName ) { $ResourceName.Value = $params[1] }

}

if ($params.Count -gt 2 )
{
if ($null -ne $MethodName) { $MethodName.Value = $params[2] }
}

if ($params.Count -gt 3 )
{
$timep = $params[3]
$error.Clear()
$itime = [int32]$timep
if (0 -ne $error.Count)
{
$error.Clear()
}
else
{
if ($itime -ge($DefaultTimeOut + $Delta))
{
if ($null -ne $timeoutInSeconds) { $timeoutInSeconds.Value = $itime - $delta }
}
}
}

return
}

#==========================================================================
# Main
#==========================================================================

$RType = "RESOURCE"
$ResourceName = ""
$MethodName = ""
$DefaultTimeOut = 300
$Delta = 60
$timeoutInSeconds = $DefaultTimeOut
$fullscriptname = $MyInvocation.MyCommand.Definition

Get-ScriptParams -fullscriptname $fullscriptname -ResourceName ([ref] $ResourceName) -MethodName ([ref] $MethodName) -timeoutInSeconds ([ref] $timeoutInSeconds)
Main


</Script></Contents>
<Unicode>true</Unicode>
</File>
<File>
<Name>Cluster.js</Name>
<Contents><Script>function alert($message)
{
WScript.Echo($message);
}

function exit($message)
{
alert($message);
WScript.Quit(0);
}

String.prototype.trim = function()
{
return this.replace(/^\s+|\s+$/gm,'');
}

String.prototype.replaceAll = function (str1, str2, ignore) {
return this.replace(new RegExp(str1.replace(/([\/\,\!\\\^\$\{\}\[\]\(\)\.\*\+\?\|\&lt;\&gt;\-\&amp;])/g, "\\$&amp;"), (ignore ? "gi" : "g")), (typeof (str2) == "string") ? str2.replace(/\$/g, "$$$$") : str2);
}


String.prototype.padRight = function ($c,$n) {
if ("number" !== typeof ($n) || "string" !== typeof ($c) || 0 === $c.length) { return this; }
if (this.length &gt;= $n) { return this; }
return this + Array($n - this.length + 1).join($c);
}

Enumerator.prototype.forEach = function($f,$params)
{
var $result = null;

if ("function" !== typeof($f)) { return undefined;}

for(;!this.atEnd();this.moveNext())
{
$result = $f(this.item(),$params);
if (undefined === $result)
{
break;
}
}

return $result;
}

function getPropCount($O)
{
var $i = 0;
for ($i in $O) { $i++; }

return $i;
}

function GetErrorDetails($e)
{
if (!($e instanceof Error)) { return; }

if ($e.number &lt;0)
{
$e.number = 0xffffffff + $e.number + 1;
}

return " Error details: Error code: 0x" + $e.number.toString(16) + ". Description : " + $e.description;
}

function getEscapedName($Name)
{
return $Name.replaceAll("\\", "\\\\").replaceAll("'", "\\'");
}

function getAescapedName($Name) {
return $Name.replaceAll("\\", "\\\\\\\\").replaceAll("\"", "\\\\\\\"");
}

function getClusterService($NodeName)
{
$wmiPath = "winmgmts:{impersonationLevel=impersonate,authenticationLevel=pktPrivacy}!\\\\" + $NodeName + "\\root\\mscluster";
var Service = null;
var $message = "";

try
{
Service = GetObject($wmiPath);
}
catch(e)
{
$message = GetErrorDetails(e);
$message = "Cannot connect to Cluster Namespace. " + $message;
exit($message);
}

return Service;
}

function GetWmiQuery($query, $Service, $message, $IsA) {
var $coll = null;
var $iterator = null;
var $Count = null;
var $Message = null;

try {
$coll = $Service.ExecQuery($query);
$Count = $coll.Count;
if (0 !== $Count) {
$iterator = new Enumerator($coll);
}
}
catch (e) {
$iterator = undefined;
if (!$IsA) {
$Message = GetErrorDetails(e);
$Message = $message + "\n" + $Message;
alert($Message);
}
}
finally {
delete $coll;
$coll = null;
}

return $iterator;

}

function GetWmiAssoc($Object, $AssocName, $message, $IsA) {
var $collection = null;
var $iterator = null;
var $Count = null;
var $Message = null;

try {
$coll = $Object.Associators_($AssocName, "", "", "", false, false, "", "", 0);
$Count = $coll.Count;
if (0 !== $Count) {
$iterator = new Enumerator($coll);
}

} catch (e) {
$iterator = undefined;
if (!$IsA) {
$Message = GetErrorDetails(e);
$Message = $message + "\n" + $Message;
alert($Message);
}
}
finally {
delete $coll
$coll = null;
}

return $iterator;

}

function checkWmiMethod($Object, $MethodName) {
if (null === $Object || undefined === $Object || null === $MethodName || undefined === $MethodName || "object" !== typeof ($Object)) {
return false;
}

var $methods = null;
var $result = true;
$methods = $Object.Methods_;

if (null === $methods || undefined === $methods || "object" !== typeof ($methods)) { delete $methods; $methods = null; return false; }
if (0 === $methods.Count || null === $methods.Count) { delete $methods; $methods = null; return false; }

try {
$methods.Item($MethodName);
} catch (e) {
$result = false;
}

delete $methods;
$methods = null;

return $result;
}

function getClusterGroup($GroupName,$Service)
{
if (undefined === $GroupName || null === $GroupName)
{
return undefined;
}

var $query = "select Name,State from MSCluster_ResourceGroup where Name='" + getEscapedName($GroupName) + "'";
var $iterator = GetWmiQuery($query,$Service,"Cannot get resource group name " + $GroupName + " . ");

return (null !== $iterator &amp;&amp; undefined !== $iterator) ? $iterator.item() : $iterator;
}

function addResource($rpath,$Resources)
{
if (undefined === $Resources || null === $Resources || "object" !== typeof ($Resources)) { return undefined; }
if (undefined === $rpath || null === $rpath || "object" !== typeof ($rpath) ) { return undefined; }
if (undefined === $rpath.Dependent || null === $rpath.Dependent || "string" !== typeof ($rpath.Dependent)) { return 0; }

var $r = null;

try {
$r = $Resources.service.Get($rpath.Dependent)
$Resources.rr.push($r);

} catch (e) {

}
finally
{
delete $r;
$r = null
}

return 0;
}

function getDependentResouces($ResourceName,$Service)
{
if (undefined === $ResourceName || null === $ResourceName) {
return undefined;
}

if (undefined === $ResourceName || null === $ResourceName || "object" !== typeof ($Service)) { return undefined; }

$ResourceName = getAescapedName($ResourceName);

var $query = "select Dependent from MSCluster_ResourceToDependentResource where Antecedent=\"MSCluster_Resource.Name=\\\"" + $ResourceName + "\\\"\"";
var $iterator = GetWmiQuery($query, $Service, "Cannot get dependent resources for " + $ResourceName + " . ");

if (null === $iterator || undefined === $iterator) { return $iterator;}
var $Resources = {rr:[],service:$Service};

if (undefined === $iterator.forEach(addResource, $Resources)) { return undefined; }
if (0 === $Resources.rr.length) { return null;}


return $Resources.rr;

}

function getClusterResource($ResourceName,$Service,$all)
{
if (undefined === $ResourceName || null === $ResourceName)
{
return undefined;
}

var $query =" from MSCluster_Resource where Name='" + getEscapedName($ResourceName) + "'"
$query = !$all ? "select Name,State" + $query : "select *" + $query;
var $iterator = GetWmiQuery($query,$Service,"Cannot get resource [" + $ResourceName + "] . ");

return (null !== $iterator &amp;&amp; undefined !== $iterator) ? $iterator.item() : $iterator;
}

function getResourceNode($r) {
if (undefined !== $r.OwnerNode &amp;&amp; null !== $r.OwnerNode) { return $r.OwnerNode; }

var $iterator = GetWmiAssoc($r, "MSCluster_NodeToActiveResource", "Cannot get active owner of resource.",true);
if (undefined === $iterator || null === $iterator) { return undefined;}
var $n = $iterator.item();
if (undefined === $n || null === $n) { return ""; }

return (null !== $n.Name &amp;&amp; undefined !== $n.Name) ? $n.Name : "";
}

function getResourceGroup($r) {

if (undefined !== $r.OwnerGroup &amp;&amp; null !== $r.OwnerGroup) {return $r.OwnerGroup;}

var $iterator = GetWmiAssoc($r, "MSCluster_ResourceGroupToResource", "Cannot get resource group.",true);
if (undefined === $iterator || null === $iterator) { return ""; }
var $g = $iterator.item();
if (undefined === $g || null === $g) { return ""; }

return (null !== $g.Name &amp;&amp; undefined !== $g.Name) ? $g.Name : "";
}

function ConvertNumericResourceStateToString($state)
{

$States = ["Inherited", "Initializing", "Online", "Offline", "Failed"];

if ($state &gt;= 0 &amp;&amp; $state &lt; 5) { return $States[$state]; }
if (128 === $state) { return "Pending"; }
if (129 === $state) { return "Online Pending"; }
if (130 === $state) { return "Offline Pending"; }

return "Unknown";
}

function ConvertNumericResourceGroupStateToString($state) {

$States = ["Online", "Offline", "Failed", "Partial Online","Pending"];

if ($state &gt;= 0 &amp;&amp; $state &lt; 5) { return $States[$state]; }

return "Unknown";
}

function getCmdFileName() {
var $f = WScript.ScriptName;
var $p = WScript.ScriptFullName;
var $nf = "";

if (undefined === $f || null === $f || "string" !== typeof ($f)) { return null; }
if (undefined === $p || null === $p || "string" !== typeof ($p)) { return null; }
if (0 === $f.length || 0 === $p.length || $p.length &lt;= $f.length) { return null; }

return $p.substring(0, $p.length - $f.length) + "vbparams.txt";
}

function parseCmd($s,$d)
{
if ("string" !== typeof ($s) || undefined === $s || null === $s ) { return null; }
if ("string" !== typeof ($d) || undefined === $d || null === $d || 0 === $d.length) { $d = "="; }

var $l = $s.length;
var $i = -1;

if (0 === $l) { return null; }

$i = $s.indexOf($d, 0)

if (-1 === $i) { return null; }

$i += $d.length;

return $l &lt;= $i ? "" : $s.slice($i,$l);
}


function getCmdParams($MaxParams) {
var $fso = null;
var $fl = null;
var $filename = getCmdFileName();
var $args = [];
var $i = 0;
var $v = null;
if (null === $filename) { return $args; }
if (undefined === $MaxParams || null === $MaxParams || "number" !== typeof ($MaxParams)) { $MaxParams = 0; }

try {
$fso = new ActiveXObject("Scripting.FileSystemObject");
if (!$fso.FileExists($filename)) { return $args; }
$fl = $fso.OpenTextFile($filename,1,false,-1);
if (null === $fl || undefined === $fl) { return null; }
$i = 0;
for (; !$fl.AtEndOfStream;) {
$v = parseCmd($fl.ReadLine(), "=");
if (null !== $v) {
$i++;
if ($i &gt; $MaxParams &amp;&amp; 0 !== $MaxParams) { break; }
$args.push($v);
}

}
} catch (e) {
$args = null;
alert("Cannot read command line parameters.");
}
finally {
if (null !== $fl &amp;&amp; 0 !== $i) { $fl.Close(); }
}

return $args;
}



var $T = { 2: "I16 ", 3: "I32 ", 4: "R32 ", 5: "R64 ", 8: "S ", 11: "B ", 13: "O ", 16: "I8 ", 17: "U8 ", 18: "U16 ", 19: "U32 ", 20: "I64 ", 21: "U64 ", 101: "Dt ", 102: "Ref", 103: "C16 " };

function getWmiRawValue($O) {

var $result = { a: false, v: null };

if (undefined === $O || null === $O) { return $result; }
if ("object" !== typeof ($O) &amp;&amp; "unknown" !== typeof ($O)) { $result.v = $O; return $result; }

var $ar = null;
$result.a = true;
$result.v = $O;

try {
$ar = $O.toArray();
}
catch (e) {
$result.a = false;
}

if (true === $result.a) { $result.v = $ar; }


return $result;
}


function printHeader($ResName,$maxN,$maxV)
{
if (0 === arguments.length || ($ResName.length &lt;= 20 &amp;&amp; $maxN &lt;= 30 &amp;&amp; $maxV &lt;= 24))
{
alert("\nListing properties for " + $ResName + ":\n");
alert("T Resource Name Value");
alert("--- -------------------- ------------------------------ ------------------------");
return;
}

var $s = "T Resource ";
var $n = "Name ";
var $nl = "--- --------------------";

if ($ResName.length &gt; 20) {
$s = $s.padRight(" ",$ResName.length + 5);
$nl = $nl.padRight("-",$ResName.length + 4);
}

$nl += " ";

if($maxN &gt; 30) {
$s += $n.padRight(" ",$maxN ) + " ";
$nl += ("------------------------------").padRight("-",$maxN) + " ";
}
else
{
$s += $n;
$nl += "------------------------------ ";
}

$s += "Value";
$nl += $maxV &gt; 24 ? ("------------------------").padRight("-",$maxV + 1) : "-----------------------";

alert($s);
alert($nl);
}

function getMaxL($p, $o)
{
if (undefined === $p || null === $p || "object" !== typeof ($p)) { return undefined; }
if (undefined === $p.Name || null === $p.Name || "string" !== typeof ($p.Name)) { return undefined; }
if (undefined === $p.CIMType || null === $p.CIMType) { return undefined; }
if ($p.Name.length &gt; $o.mN) { $o.mN = $p.Name.length; }
if (undefined === $p.Value || null === $p.Value) { return 0;}

if (8 !== $p.CIMType || 102 !== $p.CIMType) {return 0;}
if (8 === $p.CIMType &amp;&amp; undefined !== $p.Value &amp;&amp; null !== $p.Value &amp;&amp; $p.Value.length &gt; $o.mV) { $o.mV = $p.Value.length; return 0; }

return 0;
}

function getMaxDep($p, $o) {
if (undefined === $p || null === $p || "object" !== typeof ($p)) { return undefined; }
if (undefined === $p.Name || null === $p.Name || "string" !== typeof ($p.Name)) { return undefined; }

var $r = {};
$r.State = ConvertNumericResourceStateToString($p.State);
$r.Name = $p.Name;
$r.Node = getResourceNode($p);
if ($r.Name.length &gt; $o.mR) { $o.mR = $p.Name.length; };
if ($r.State.length &gt; $o.mS) { $o.mS = $r.State.length; }
if ($r.Node.length &gt; $o.mN) { $o.mN = $r.Node.length; }

$o.rd.push($r);

return 0;
}

function getSvalue($p)
{
var $oV = getWmiRawValue($p.Value)

if (null === $oV.v) { return ""; }

if (true ===$oV.a)
{
//Not Object or Reference
if (13 !== $p.CIMType || 102 !== $p.CIMType)
{
try {
$oV.v = $oV.v.join(",");
} catch (e) {
$oV.v = 0 === $oV.v.length ? "" : $oV.v[0];

}
}
else
{
return $p.Name
}
}


if (8 === $p.CIMType || 103 === $p.CIMType || 4 === $p.CIMType || 5 === $p.CIMType || 102 === $p.CIMType) { return $oV.v; }
if (11 === $p.CIMType) { return $oV.v.toString(); }

if (2 === $p.CIMType || 18 === $p.CIMType) { return "number" !== typeof($oV.v) ? "" : $oV.v &gt;= 0 ? $oV.v.toString(10) + " (0x" + $oV.v.toString(16) + ")" : $oV.v.toString(10) + " (0x" + (0xffff + $oV.v + 1).toString(16) + ")"; }
if (3 === $p.CIMType ) { return "number" !== typeof($oV.v) ? "" : $oV.v &gt;= 0 ? $oV.v.toString(10) + " (0x" + $oV.v.toString(16) + ")" : $oV.v.toString(10) + " (0x" + (0xffffffff + $oV.v + 1).toString(16) + ")"; }
if (16 === $p.CIMType || 17 === $p.CIMType) { return "number" !== typeof ($oV.v) ? "" : $oV.v &gt;= 0 ? $oV.v.toString(10) + " (0x" + $oV.v.toString(16) + ")" : $oV.v.toString(10) + " (0x" + (0xff + $oV.v + 1).toString(16) + ")"; }
if ($p.CIMType &gt;= 17 &amp;&amp; $p.CIMType &lt;= 19) { return "number" !== typeof ($oV.v) ? "" : $oV.v.toString(10) + " (0x" + $oV.v.toString(16) + ")"; }
if (20 === $p.CIMType || 21 === $p.CIMType) { return "number" === typeof($oV.v) ? $oV.v.toString(10) : $oV.v; }

return "";
}

function printProp($p, $o) {
if (undefined === $p || null === $p || "object" !== typeof ($p)) { return undefined; }
if (undefined === $p.Name || null === $p.Name || "string" !== typeof ($p.Name)) { return undefined; }
if (undefined === $p.CIMType || null === $p.CIMType) { return undefined; }

var $pt = $T[$p.CIMType];
if (undefined === $pt || null === $pt) { $pt = "UKN "; }
var $s = $pt + $o.rN + " " + $p.Name.padRight(" ", $o.mN) + " ";

if (null !== $p.Value &amp;&amp; undefined !== $p.Value) { $s += getSvalue($p);}
alert($s)

return 0;
}

function printDep($r)
{
if (null === $r || undefined === $r || "object" !== typeof ($r)) { alert("Wrong resource provided."); return; }
if (false === checkWmiMethod($r, "GetDependencies")) { return; }

var $D = null;
var $s = "Listing resource dependency expression for '" + $r.Name + "':";
var $l = $s.length;

try {
$D = $r.ExecMethod_("GetDependencies");
if (null === $D || undefined === $D || "object" !== typeof ($D)) { return; }
if (undefined === $D.Expression || null === $D.Expression || "string" !== typeof ($D.Expression)) { return; }
if ($l &lt; $D.Expression.length) { $l = $D.Expression.length; }
alert($s);
alert(("-").padRight("-", $l));
alert($D.Expression);
} catch (e) {

}

return;
}

function printDepsHeader($r,$null,$mR,$mG,$mN,$mS)
{

if (true === $null)
{
alert(" Resource Group Node Status");
alert(" ------------ -------- ----- -------");
return;
}


alert(("Resource ").padRight(" ",$mR) + " " + ("Group ").padRight(" ",$mG) + " " + ("Node").padRight(" ",$mN) + " Status");
alert(("------------").padRight("-",$mR) + " " + ("--------").padRight("-",$mG) + " " + ("----").padRight("-",$mN) + " " + ("-------").padRight("-",$mS));
}

function printDeps($r, $Service) {
if (null === $r || undefined === $r || "object" !== typeof ($r)) { alert("Wrong resource provided."); return; }
var $it = getDependentResouces($r.Name,$Service);

if (undefined === $it) { return; }
if (null === $it) {
printDep($r);
alert("\nListing resource dependencies for '" + $r.Name + "':\n\n");
printDepsHeader($r, true);
alert("\n");

return;
}
var $g = getResourceGroup($r);
if ($g.length &lt; 10) { $g = $g.padRight(" ", 10);}
var $p = { mR: 10, mG: $g.length &gt;10 ? $g.length: 10, mN: 5, mS: 6,rd:[]};
var $i = 0;

printDep($r);
try {
for (; $i &lt; $it.length; $i++)
{
if (undefined === getMaxDep($it[$i], $p)) { return; }
}

$i = 0;

alert("\nListing resource dependencies for '" + $r.Name + "':\n\n");
printDepsHeader($r, false, $p.mR, $p.mG, $p.mN, $p.mS);
for(;$i &lt; $p.rd.length;$i++)
{
alert($p.rd[$i].Name.padRight(" ", $p.mR) + " " + $g + " " + $p.rd[$i].Node.padRight(" ", $p.mN) + " " + $p.rd[$i].State);
}
alert("\n");
} catch (e) {

}

return;
}

function printResStatus($r) {
if (null === $r || undefined === $r || "object" !== typeof ($r)) { alert("Wrong resource provided."); return; }

var $g = getResourceGroup($r);
if ($g.length &lt; 10) { $g = $g.padRight(" ", 10); }
var $p = { mR: 10, mG: $g.length &gt; 10 ? $g.length : 10, mN: 5, $mS: 6, rd: [] };
var $i = 0;

try {
if (undefined === getMaxDep($r, $p)) { return; }
alert("\n Listing resource status for '" + $r.Name + "':\n\n");
printDepsHeader($r, false, $p.mR, $p.mG, $p.mN, $p.$mS);
for (; $i &lt; $p.rd.length; $i++) {
alert($p.rd[$i].Name.padRight(" ", $p.mR) + " " + $g + " " + $p.rd[$i].Node.padRight(" ", $p.mN) + " " + $p.rd[$i].State);
}

alert("\n\n");
} catch (e) {

}

return;
}

function getObjectProperties($O)
{
if (null === $O || undefined === $O || "object" !== typeof($O)) { alert("Wrong resource provided."); return; }
if (undefined === $O.Properties_ || null === $O.Properties_) { printHeader(); return; }
if ("object" !== typeof ($O.Properties_)) { printHeader(); return; }
if (0 === $O.Properties_.Count || undefined === $O.Properties_.Count) { printHeader(); return; }

var $p = { mN: 30, mV: 24, rN: (undefined === $O.Name || null === $O.Name) ? " " : $O.Name.padRight(" ", 20) };
var $pE = null;
var $Message = null;

try {
$pE = new Enumerator($O.Properties_);
if (null === $pE) { printHeader(); return; }
if (undefined === $pE.forEach(getMaxL, $p)) { return; }
$pE.moveFirst();
printHeader($p.rN, $p.mN, $p.mV);
if (undefined === $pE.forEach(printProp, $p)) { return; }
} catch (e) {
$Message = GetErrorDetails(e);
$Message = "Cannot get properties of resource " + $O.Name + " . " + $Message;
alert($Message);
}

}

function bringOnOff($Resource, $IsOnline, $Service, $timeoutInSeconds) {
alert("The state of the resource " + $Resource.Name + " is " + ConvertNumericResourceStateToString($Resource.State));
var $message = "";

try {
if (!$IsOnline) {
if (2 === $Resource.State || 4 === $Resource.State) {
alert("Attempting to bring the resource offline.");
$Resource.TakeOffline($timeoutInSeconds);
}
else {
alert("Resource is already offline or in an incompatible state.");
return;
}
}
else {
if (3 === $Resource.State || 4 === $Resource.State) {
alert("Attempting to bring the resource online");
$Resource.BringOnline($timeoutInSeconds);
}
else {
alert("Resource is already online or in an incompatible state.");
return;
}
}

} catch (e) {
$message = GetErrorDetails(e);
$message = "Attempt failed with error. " + $message;
alert($message);
return;
}

var $oResource = null;
try {
$oResource = $Service.Get($Resource.Path_);
alert("The state of the resource " + $oResource.Name + " is " + ConvertNumericResourceStateToString($oResource.State));

} catch (e) {
$message = GetErrorDetails(e);
$message = "Cannot get resource state. " + $message;
alert($message);
}

delete $oResource;
$oResource = null;

return;
}

function getParams($params) {

if ("object" !== typeof ($params)) {
return false;
}

var $args = getCmdParams(4);

if (null === $args) { exit("");}

$params.timeoutInSeconds = 300;

if ($args.length &lt; 3) {
exit("Wrong number of arguments.");
}
else if ($args.length &gt; 3) {
$params.timeoutInSeconds = parseInt($args[3], 10);
if (isNaN($params.timeoutInSeconds)) {
$params.timeoutInSeconds = 300;
}
}

$params.oType = $args[0];
$params.ResourceName = $args[1];
$params.MethodName = $args[2];


if (0 === $params.oType.length || 0 === $params.oType.trim().length) {
exit("Cluster object type is empty.");
}

if ("resource" !== $params.oType.toLowerCase() ) {
exit("Cluster object type " + $params.oType + " is not supported.");
}

if (0 === $params.ResourceName.length || 0 === $params.ResourceName.trim().length) {
exit("Resource Name is empty.");
}

if (0 === $params.MethodName.length || 0 === $params.MethodName.trim().length) {
$params.MethodName = "/status";
}

$params.MethodName = $params.MethodName.toLowerCase();

if ("/online" !== $params.MethodName &amp;&amp; "/offline" !== $params.MethodName &amp;&amp; "/prop" !== $params.MethodName &amp;&amp; "/listdep" !== $params.MethodName &amp;&amp; "/status" !== $params.MethodName) {
exit("[Error]: Unrecognized method " + $params.MethodName + " used");
}

return true;
}

function Main()
{
var $params = {};

getParams($params);


var $Service = null;
var $oResource = null;

$Service = getClusterService(".");
if ("/prop" === $params.MethodName){$oResource = getClusterResource($params.ResourceName, $Service,true);}
else{ $oResource = getClusterResource($params.ResourceName, $Service); }

if (null === $oResource)
{
delete $Service;
$Service = null;
exit("Cluster resource " + $params.ResourceName + " is not found.");
}
else if (undefined === $oResource)
{
delete $Service;
$Service = null;
exit("");
}

if ("/online" === $params.MethodName)
{
bringOnOff($oResource, true, $Service, $params.timeoutInSeconds);
}
else if("/offline" === $params.MethodName)
{
bringOnOff($oResource, false, $Service, $params.timeoutInSeconds);
}
else if("/prop" === $params.MethodName)
{

getObjectProperties($oResource);
}
else if("/listdep" === $params.MethodName)
{
alert("\n");
printDeps($oResource,$Service);
}
else
{
printResStatus($oResource);
}

delete $oResource;
delete $Service;
$oResource = null;
$Service = null;
}

Main();
</Script></Contents>
<Unicode>true</Unicode>
</File>
<File>
<Name>vbparams.txt</Name>
<Contents><Script>

=$Config/ResourceType$
=$Config/ResourceName$
=$Config/Command$
=$Config/TimeoutSeconds$

</Script></Contents>
<Unicode>true</Unicode>
</File>
<File>
<Name>psparams.txt</Name>
<Contents><Script>

=$Config/ResourceType$
=$Config/ResourceName$
=$Config/Command$
=$Config/TimeoutSeconds$

</Script></Contents>
<Unicode>true</Unicode>
</File>
</Files>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="WA"/>
</Composition>
</Composite>
</ModuleImplementation>
<InputType>System!System.BaseData</InputType>
</WriteActionModuleType>