$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.
#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 shared volume discovery data.
# PARAMETERS: void
#*********************************************************************************************
Function Main()
{
Function Set-PerfDataFromList($list, $objMomScriptAPI)
{
$ErrorActionPreference = 'SilentlyContinue' # Scoped only to function
$error.Clear()
if ($null -eq $objMomScriptAPI)
{
return
}
foreach($data in $list)
{
#Add the values for the perf counter#s object name, counter name, instance name and the value)
if(($data.$PERFORMANCE_OBJECT_NAME -eq $null) -or ($data.$PERFORMANCE_OBJECT_NAME -eq "")){
continue
}
$objTypedPropertyBag = $objMomScriptAPI.CreateTypedPropertyBag($PERFORMANCE_DATA_TYPE)
$objTypedPropertyBag.AddValue($PERFORMANCE_OBJECT_NAME, $data.$PERFORMANCE_OBJECT_NAME)
$objTypedPropertyBag.AddValue($PERFORMANCE_COUNTER_NAME, $data.$PERFORMANCE_COUNTER_NAME)
$objTypedPropertyBag.AddValue($PERFORMANCE_INSTANCE_NAME, $data.$PERFORMANCE_INSTANCE_NAME)
if($data.$PERFORMANCE_VALUE_NAME -eq $null)
{
$objTypedPropertyBag.AddValue($PERFORMANCE_VALUE_NAME, 0)
}else{
$objTypedPropertyBag.AddValue($PERFORMANCE_VALUE_NAME, $data.$PERFORMANCE_VALUE_NAME)
}
#Necessary information for the property bag data source filter condition
#to enable Agent cook down
$objTypedPropertyBag.AddValue($INSTANCE_NAME, $data.$INSTANCE_NAME)
$objTypedPropertyBag
#$objMomScriptAPI.Return($objTypedPropertyBag)
}
$error.Clear()
}
Function Get-PerfDataWmi($objMomScriptAPI,[ref]$blnSuccess,$useCim)
{
$blnSuccess.Value = $false
$ErrorActionPreference = 'SilentlyContinue' # Scoped only to function
$error.Clear()
$list = New-Object System.Collections.ArrayList($null)
#****************************************************************************************************************
# FUNCTION: CreateMonitoringData
# DESCRIPTION: Create monitoring data for a cluster shared volume.
#
# PARAMETERS: IN Object objClusterSharedVolume: the cluster shared volume as SWbemObject of type MSCluster_ClusterSharedVolume.
# 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
# RETURNS: Boolean: True if successful
#****************************************************************************************************************
Function CreateMonitoringData($objClusterSharedVolume, $objClusterDiskPartition, $objClusterResource,$list) #As Boolean
{
$ErrorActionPreference = 'SilentlyContinue' # Scoped only to function
$error.Clear()
#Create performance data
if ($null -eq $list)
{
$error.Clear()
return
}
#***************************************************************************************
# PROCEDURE: CreatePerformanceTypedPropertyBag
# DESCRIPTION: Generates a performance typed property bag and adds it to the script#s XML output.
# PARAMETERS: IN String strObjectName: name of the performance object
# IN String strCounterName: name of the performance counter
# IN String strInstanceName: name of the performance counter in instance
# IN Variant varValue: value of the performance counter
# IN String strCSVInstanceName: Friendly volume name of the cluster shared volume
# IN Object objMomScriptAPI: initialised MOM.ScriptAPI object
#***************************************************************************************
Function CreatePerformanceTypedPropertyBag($strObjectName, $strCounterName, $strInstanceName,$varValue, $strCSVInstanceName)
{
return @{ $PERFORMANCE_OBJECT_NAME = $strObjectName;
$PERFORMANCE_COUNTER_NAME = $strCounterName;
$PERFORMANCE_INSTANCE_NAME = $strInstanceName;
$PERFORMANCE_VALUE_NAME = $varValue;
$INSTANCE_NAME = $strCSVInstanceName}
}
################################################################
##Common Functions
################################################################
$CIM_ERROR_INVALIDCLASS = 2147749902
$CIM_ERROR_INVALIDNAMESPACE = 2147749904
$WMI_ERROR_INVALIDCLASS = -2147217392
$WMI_ERROR_INVALIDNAMESPACE = -2147217394
$WMI_CLUSTER_RESOURCE_TO_DISKPARTITION_CLASS = "MSCluster_ResourceToDiskPartition"
$WMI_MSCLUSTER_RESOURCE_CLASS = "MSCluster_Resource"
$WMI_CLUSTER_SHARED_VOLUME_TO_PARTITION_ASSOCIATOR_CLASS = "MSCluster_ClusterSharedVolumeToPartition"
$WMI_CLUSTER_SHARED_VOLUME_TO_RESOURCE_ASSOCIATOR_CLASS = "MSCluster_ClusterSharedVolumeToResource"
$WMI_ASSOCIATOR_DELIMITER = "="
$WMI_ASSOCIATOR_TRIMSYMBOL = """"
$WMI_ESCAPE_QUOTESYMBOL = "\"""
$WMI_SINGLE_QUOTESYMBOL = "'"
$WMI_ESCAPE_SINGLE_QUOTESYMBOL = "\'"
$WMI_ESCAPE_BACKSLASH_SYMBOL = "\\"
Function Check-WmiExceptions($Exception,[bool]$UseCim)
{
$result = $false
Function Get-ComputerName([string]$strTargetComputer)
{
$ErrorActionPreference = 'SilentlyContinue' # Scoped only to function
$error.Clear()
$strTargetComputerShortName = $strTargetComputer
Function Throw-ScriptError([string]$Message)
{
throw $Message
exit
}
Function Get-CSVResource([string]$VolumeId,[hashtable]$VolumeToResource)
{
if ($null -eq $VolumeToResource -or [string]::IsNullOrEmpty($VolumeId))
{
return $null
}
$CsvResource = $VolumeToResource[$VolumeId]
return $CsvResource
}
Function Get-CSVPartition([string]$VolumeId,[hashtable]$VolumeToPartition)
{
if ($null -eq $VolumeToPartition -or [string]::IsNullOrEmpty($VolumeId))
{
return $null
}
$CsvPartition = $VolumeToPartition[$VolumeId]
return $CsvPartition
}
Function Get-ResourceNameToVolumeTable([bool]$useCim,[hashtable]$ResourceToVolume)
{
$ErrorActionPreference = 'SilentlyContinue' # Scoped only to function
$error.Clear()
if ($null -eq $ResourceToVolume)
{
return $false
}
Function Get-VolumeToPartitionTable([bool]$useCim,[hashtable]$VolumeToPartition)
{
$ErrorActionPreference = 'SilentlyContinue' # Scoped only to function
$error.Clear()
if ($null -eq $VolumeToPartition)
{
return $false
}
foreach ($Partition in $Partitions)
{
$VolumeToPartition[$Partition.Path] = $Partition
}
return $true
}
Function Get-ResourceNameToResourceTable([bool]$useCim,[hashtable]$NameToResource,[string]$Filter)
{
$ErrorActionPreference = 'SilentlyContinue' # Scoped only to function
$error.Clear()