#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()
{
$ErrorActionPreference = 'SilentlyContinue'
$error.Clear()
$objMomScriptAPI = New-Object -comObject MOM.ScriptAPI -ErrorAction SilentlyContinue
if ($null -eq $objMomScriptAPI)
{
exit -1
}
$useCIM = CheckCmdLets
$error.Clear()
#Create new discovery data object
$objDiscoveryData = $objMomScriptAPI.CreateDiscoveryData(0, $strSourceID, $strManagedEntityId)
if ($error.Count -ne 0)
{
LogScriptEvent -LogType 0 -EventId $EVENT_ID_SCRIPTERROR -EventLevel $EVENT_TYPE_WARNING -Message "`nAn error occurred while running script. Cannot Creata Discovery Data Object" -objMomScriptAPI $objMomScriptAPI
exit -1
}
$strClusterName = Get-ClusterName -useCim $useCIM
If ([string]::IsNullOrEmpty($strClusterName) )
{
exit -1
}
if ($error.Count -ne 0)
{
return $SCRIPT_WITH_ERROR
}
}
return $intSuc
}
#****************************************************************************************************************
# FUNCTION: DiscoverClusterSharedVolumes
# DESCRIPTION: Discover instances of the class #Microsoft.Windows.Server.ClusterSharedVolumeMonitoring.ClusterSharedVolume# 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 DiscoverClusterSharedVolumes([string]$strTargetComputer, [string]$strClusterName, $objDiscoveryData,$useCIM) #As Integer
{
$strTargetComputerShortName = Get-ComputerName -strTargetComputer $strTargetComputer
$blnCreateDiscoveryData = ($strTargetComputerShortName -ieq $strClusterName)
if (-Not $blnCreateDiscoveryData)
{
return $SCRIPT_SUCCESS
}
#****************************************************************************************************************
# FUNCTION: CreateDiscoveryData
# DESCRIPTION: Create discovery data for
# <ClassType ID="Microsoft.Windows.Server.ClusterSharedVolumeMonitoring.ClusterSharedVolume" Accessibility="Internal" Abstract="false" Base="Windows!Microsoft.Windows.ApplicationComponent" Hosted="true" Singleton="false">
# <Property ID="ClusterSharedVolumeName" Type="string" Key="true" CaseSensitive="false" Length="256" MinLength="0" />
# <Property ID="FriendlyVolumeName" Type="string" Key="false" CaseSensitive="false" Length="256" MinLength="0" />
# <Property ID="PartitionName" Type="string" Key="false" CaseSensitive="false" Length="256" MinLength="0" />
# <Property ID="PartitionFileSystem" Type="string" Key="false" CaseSensitive="false" Length="256" MinLength="0" />
# <Property ID="PartitionSize" Type="int" Key="false" />
# <Property ID="ClusterName" Type="string" Key="false" CaseSensitive="false" Length="256" MinLength="0" />
# <Property ID="VolumeLabel" Type="string" Key="false" CaseSensitive="false" Length="256" MinLength="0" />
# </ClassType>
#
# 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
# OUT Object objDiscoveryData: initialised DiscoveryData instance
# RETURNS: Integer: 0 if successful or 1 if Error
#****************************************************************************************************************
Function CreateDiscoveryData($objClusterSharedVolume, $objClusterDiskPartition, $objClusterResource,$strTargetComputer, $strClusterName, $objDiscoveryData) #As Integer
{
$ErrorActionPreference = 'SilentlyContinue' # Scoped only to function
$error.Clear()
$iResult = $SCRIPT_WITH_ERROR
#Create the cluster shared volume instance hosted on the targeted cluster virtual server
$objCSVInstance = $objDiscoveryData.CreateClassInstance($CSVolumeClassName)
$strCSVName = $objClusterResource.$WMI_NAME_PROPERTY_NAME + "_" + $objClusterSharedVolume.$WMI_NAME_PROPERTY_NAME
if ($strCSVName.Length -gt $MAX_FIELD_LENGTH)
{
$strCSVName = $strCSVName.Substring(0,$MAX_FIELD_LENGTH)
}
Function Get-ComputerName([string]$strTargetComputer)
{
$ErrorActionPreference = 'SilentlyContinue' # Scoped only to function
$error.Clear()
$strTargetComputerShortName = $strTargetComputer