Windows 装入点发现数据源

Microsoft.Windows.Server.10.0.MountPointDiscovery.ModuleType (DataSourceModuleType)

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityInternal
RunAsSystem.PrivilegedMonitoringAccount
OutputTypeSystem.Discovery.Data

Member Modules:

ID Module Type TypeId RunAs 
Scheduler DataSource System.Discovery.Scheduler Default
ScriptProbe ProbeAction Microsoft.Windows.Server.10.0.PowerShellDiscoveryProbe Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
IntervalSecondsint$Config/IntervalSeconds$间隔(秒)
TimeoutSecondsint$Config/TimeoutSeconds$超时(秒)

Source Code:

<DataSourceModuleType ID="Microsoft.Windows.Server.10.0.MountPointDiscovery.ModuleType" RunAs="System!System.PrivilegedMonitoringAccount" Accessibility="Internal">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ComputerName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ComputerID" type="xsd:string"/>
<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="TimeoutSeconds" type="xsd:int"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="TimeoutSeconds" ParameterType="int" Selector="$Config/TimeoutSeconds$"/>
</OverrideableParameters>
<ModuleImplementation>
<Composite>
<MemberModules>
<DataSource ID="Scheduler" TypeID="System!System.Discovery.Scheduler">
<Scheduler>
<SimpleReccuringSchedule>
<Interval Unit="Seconds">$Config/IntervalSeconds$</Interval>
</SimpleReccuringSchedule>
<ExcludeDates/>
</Scheduler>
</DataSource>
<ProbeAction ID="ScriptProbe" TypeID="Microsoft.Windows.Server.10.0.PowerShellDiscoveryProbe">
<ScriptName>Microsoft.Windows.Server.10.0.MountPointDiscovery.ModuleType.ps1</ScriptName>
<PSparam>param ($SourceID, $ManagedEntityId, $TargetComputer, $TargetComputerID)</PSparam>
<ScriptBody><Script>#Copyright (c) Microsoft Corporation. All rights reserved.

# Parameters that should be passed to this script
# 0 MPElement ID ($MPElement$)
# 1 Target Id for ME this rule is running against ($Target/Id$)
# 2 Computer (FQDN) that the Mount Point will be hosted on
# 3 Computer ID (Key) that the Mount Point will be hosted on

Function Main()
{
$ClusterVolumes = @{}
$IsCluster = CheckCluster $TargetComputer

if ($IsCluster -eq $true)
{
$ClusterVolumes = GetClusterDiskPartitionCollection $TargetComputer
}

$oDiscoveryData = $momAPI.CreateDiscoveryData(0, $SourceID, $ManagedEntityId)

if ((DoDiscovery $TargetComputer $TargetComputerID $oDiscoveryData $IsCluster $ClusterVolumes) -ne 0)
{
$oDiscoveryData = $momAPI.CreateDiscoveryData(0, $SourceID, $ManagedEntityId)
$oDiscoveryData.IsSnapshot = $false
}

$oDiscoveryData
}


#---------------------------------------------------------------------------
# Function: DoDiscovery
# Usage:
# Parameter (sTargetComputer, sTargetComputerID, oDisc)
# Returns the Discovery Data Collection
#---------------------------------------------------------------------------
Function DoDiscovery
{
param ([string]$sTargetComputer, [string]$sTargetComputerID, $oDisc,$IsCluster, [hashtable]$ClusterVolumes)

$error.Clear()
$IsNano = Is_NanoServer
if ( $true -eq $IsNano)
{
$IsLoad = Load-Module -ModuleName "Storage"

if($false -eq $IsLoad)
{
return 1

}

$iResult = DiscoverOnNano -oDisc $oDisc -sTargetComputerID $sTargetComputerID -ClusterVolumes $ClusterVolumes -IsCluster $IsCluster
}
else
{
$error.Clear()
$iResult = DoFullDiscovery -oDisc $oDisc -sTargetComputer $sTargetComputer -sTargetComputerID $sTargetComputerID -ClusterVolumes $ClusterVolumes -IsCluster $IsCluster


}

return $iResult
}


Function DiscoverOnNano ($oDisc,$sTargetComputerID,[hashtable]$ClusterVolumes,$IsCluster)
{
if ([string]::IsNullOrEmpty($sTargetComputerID) -or $null -eq $oDisc )
{
return 1
}

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

$objVolumes = Get-Volume

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

$errorCount = 0
foreach ($objVol in $objVolumes)
{
$DeviceId = $objVol.UniqueId
$DriveLetter = $objVol.Driveletter
$IsClusterVolume = CheckIsClusterVolume -sDeviceID $DeviceId -IsCluster $IsCluster -ClusterVolumes $ClusterVolumes
if([string]::IsNullOrEmpty($Driveletter) -and ($objVol.DriveType -eq "Fixed") -and ($IsClusterVolume -eq $false) -and $false -eq [string]::IsNullOrEmpty($DeviceId))
{
$oInstance = $oDisc.CreateClassInstance("$MPElement[Name='Microsoft.Windows.Server.10.0.LogicalDisk']$")
if ($null -eq $oInstance -or $null -eq $objVol)
{
continue
}

Add-VolumePropertyNano -oInstance $oInstance -objVol $objVol -sTargetComputerID $sTargetComputerID
if(0 -eq $error.Count)
{
$oDisc.AddInstance($oInstance)
}

}
$errorCount += $error.Count
$error.Clear()
}

return $errorCount
}

Function DoFullDiscovery($oDisc,$sTargetComputer,$sTargetComputerID,[hashtable]$ClusterVolumes,$IsCluster)
{

$objVolumes = WMIGetInstanceNoAbort $sTargetComputer "root\cimv2" ("Win32_Volume where DriveType = 3 and driveletter = null")
$ErrorCount = $error.Count
if ($ErrorCount -ne 0)
{
return 1
}

$MountPoints = Get-MountPoints -sTargetComputer $sTargetComputer
$ErrorCount = $error.Count
$MountDirs = Get-MountDirs -sTargetComputer $sTargetComputer
$ErrorCount += $error.Count
if ($ErrorCount -ne 0)
{
return 1
}

$ErrorActionPreference="SilentlyContinue"

foreach ($objVol in $objVolumes)
{
$DeviceId = $objVol.DeviceID
$IsClusterVolume = CheckIsClusterVolume -sDeviceID $DeviceId -IsCluster $IsCluster -ClusterVolumes $ClusterVolumes
$VolName = StripEndChar -sName $objVol.Name
$VolName = Get-MountDir -MountPoints $MountPoints -MountDirs $MountDirs -VolName $VolName -VolId $DeviceId

if($false -eq $IsClusterVolume -and $false -eq [string]::IsNullOrEmpty($VolName) )
{
$VolumeName = Get-StringProperty -Property $objVol.Label
$oInstance = $oDisc.CreateClassInstance("$MPElement[Name='Microsoft.Windows.Server.10.0.LogicalDisk']$")
$oInstance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.LogicalDevice']/DeviceID$", $VolName)
$oInstance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.LogicalDevice']/Name$", $VolName )
$oInstance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $sTargetComputerID)
$oInstance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.LogicalDevice']/Description$", "Mounted Disk") #"Description" property of win32_volume is &lt;null&gt;
$oInstance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.LogicalDisk']/VolumeName$", $VolumeName)
$oInstance.AddProperty("$MPElement[Name='WindowsServer!Microsoft.Windows.Server.LogicalDisk']/FileSystem$", $objVol.FileSystem)
$oInstance.AddProperty("$MPElement[Name='WindowsServer!Microsoft.Windows.Server.LogicalDisk']/Compressed$", $objVol.Compressed)
$oInstance.AddProperty("$MPElement[Name='WindowsServer!Microsoft.Windows.Server.LogicalDisk']/Size$", $objVol.Capacity)
$oInstance.AddProperty("$MPElement[Name='WindowsServer!Microsoft.Windows.Server.LogicalDisk']/SizeNumeric$", -1)
$oInstance.AddProperty("$MPElement[Name='WindowsServer!Microsoft.Windows.Server.LogicalDisk']/SizeInMBs$", (ExpressedInMB $objVol.Capacity) )
$oInstance.AddProperty("$MPElement[Name='WindowsServer!Microsoft.Windows.Server.LogicalDisk']/DriveType$", $objVol.DriveType)
$oInstance.AddProperty("$MPElement[Name='WindowsServer!Microsoft.Windows.Server.LogicalDisk']/SupportsDiskQuota$", $objVol.SupportsDiskQuotas)
$oInstance.AddProperty("$MPElement[Name='WindowsServer!Microsoft.Windows.Server.LogicalDisk']/QuotasDisabled$", (SwitchBoolean $objVol.QuotasEnabled) )
$oInstance.AddProperty("$MPElement[Name='WindowsServer!Microsoft.Windows.Server.LogicalDisk']/SupportsFileBasedCompression$", $objVol.SupportsFileBasedCompression)

if (0-eq $error.Count)
{
$oDisc.AddInstance($oInstance)
}
}

$errorCount += $error.Count
$error.Clear()

}

return $errorCount
}

Function Add-VolumePropertyNano($oInstance,$objVol,[string]$sTargetComputerID)
{
if ($null -eq $oInstance -or $null -eq $objVol -or [string]::IsNullOrEmpty($sTargetComputerID) )
{
return
}

$VolumeName = Get-StringProperty -Property $objVol.FileSystemLabel
$oInstance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $sTargetComputerID)
$oInstance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.LogicalDevice']/DeviceID$", (StripEndChar $objVol.UniqueId) )
$oInstance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.LogicalDevice']/Name$", (StripEndChar $objVol.UniqueId) )
$oInstance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.LogicalDevice']/Description$", "Mounted Disk")
$oInstance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.LogicalDisk']/VolumeName$", $VolumeName)
$oInstance.AddProperty("$MPElement[Name='WindowsServer!Microsoft.Windows.Server.LogicalDisk']/FileSystem$", $objVol.FileSystem)
$oInstance.AddProperty("$MPElement[Name='WindowsServer!Microsoft.Windows.Server.LogicalDisk']/Size$", $objVol.Size)
$oInstance.AddProperty("$MPElement[Name='WindowsServer!Microsoft.Windows.Server.LogicalDisk']/SizeNumeric$", -1)
$oInstance.AddProperty("$MPElement[Name='WindowsServer!Microsoft.Windows.Server.LogicalDisk']/SizeInMBs$", (ExpressedInMB $objVol.Size) )
$oInstance.AddProperty("$MPElement[Name='WindowsServer!Microsoft.Windows.Server.LogicalDisk']/DriveType$", $objVol.DriveType)

}

#---------------------------------------------------------------------------
# Function: StripEndChar
# Usage:
# Parameter (sName)
# Returns the sName without last special Character "\"
#---------------------------------------------------------------------------
Function StripEndChar([string]$sName)
{
if ([string]::IsNullOrEmpty($sName))
{
return [string]::Empty
}
else
{
return $sName.Substring(0, $sName.Length-1)
}
}




Function CheckIsClusterVolume
{
param ([string]$sDeviceID, [bool]$IsCluster, [hashtable]$ClusterVolumes)

$bFlag = $false

if ($IsCluster -eq $false -or [string]::IsNullOrEmpty($sDeviceID) -or $null -eq $ClusterVolumes )
{
return $bFlag
}

$ClusterVolId = $ClusterVolumes[$sDeviceID]
$bflag = $ClusterVolId -ne $null

return $bFlag
}

Function GetClusterDiskPartitionCollection
{
param ([string]$sTargetComputer)

$error.Clear()
$Volumes = @{}

$oInstances = WMIExecQueryNoAbort $sTargetComputer "root\MSCluster" "Select VolumeGuid From MSCluster_DiskPartition"

if ($error.Count -eq 0)
{
foreach ($item in $oInstances)
{
$VolumeId = "\\?\Volume$($item.VolumeGuid)\"
$VolumeId2 = "\\?\Volume{$($item.VolumeGuid)}\"
$Volumes[$VolumeId] = $VolumeId
$Volumes[$VolumeId2] = $VolumeId2

}
}

return $Volumes
}


Function Get-MountDir($MountPoints,$MountDirs,[string]$VolName,[string]$VolId)
{
if ($null -eq $MountPoints -or $null -eq $MountDirs)
{
return $VolName
}

if ( [string]::IsNullOrEmpty($VolName) -or [string]::IsNullOrEmpty($VolId) )
{
return [string]::Empty
}

$MptDirs = $MountPoints[$VolId]
if ($null -eq $MptDirs -or 0 -eq $MptDirs.Count)
{
return [string]::Empty
}

$MountDir = [string]::Empty
foreach ($Dir in $MptDirs.Keys)
{
if ($null -ne $MountDirs[$Dir])
{
$MountDir = $Dir
break
}
}

return $MountDir

}

Function Get-MountPoints($sTargetComputer)
{
$ErrorActionPreference="SilentlyContinue"
$error.Clear()

$MntPoints = @{}

if ([string]::IsNullOrEmpty($sTargetComputer))
{
return $MntPoints
}

$oMnts = WMIGetInstanceNoAbort $sTargetComputer "root\cimv2" "Win32_MountPoint"
foreach($oMnt in $oMnts)
{
$Dir = $oMnt.Directory.Name
$VolId = $oMnt.Volume.DeviceID

if ($true -eq [string]::IsNullOrEmpty($Dir) -or $true -eq [string]::IsNullOrEmpty($VolId) -or $Dir.Length -le $DriveLetterMaxSize)
{
continue
}

$Dirs = $MntPoints[$VolId]
if ($null -eq $Dirs)
{
$Dirs = @{}
}

$Dirs[$Dir] = $Dir

$MntPoints[$VolId] = $Dirs
}

return $MntPoints
}

Function Get-MountDirs($sTargetComputer)
{
$ErrorActionPreference="SilentlyContinue"
$error.Clear()

$MntDirs = @{}

if ([string]::IsNullOrEmpty($sTargetComputer))
{
return $MntPoints
}

$oMnts = WMIGetInstanceNoAbort $sTargetComputer "root\cimv2" "Win32_PerfFormattedData_PerfDisk_LogicalDisk"
foreach($oMnt in $oMnts)
{
$Dir = $oMnt.Name
if ($true -eq [string]::IsNullOrEmpty($Dir) -or $Dir.Length -le $DriveLetterMaxSize)
{
continue
}

$MntDirs[$Dir] = $Dir
}

return $MntDirs
}




Main</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>SourceID</Name>
<Value>$MPElement$</Value>
</Parameter>
<Parameter>
<Name>ManagedEntityId</Name>
<Value>$Target/Id$</Value>
</Parameter>
<Parameter>
<Name>TargetComputer</Name>
<Value>$Config/ComputerName$</Value>
</Parameter>
<Parameter>
<Name>TargetComputerID</Name>
<Value>$Config/ComputerID$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="ScriptProbe">
<Node ID="Scheduler"/>
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Discovery.Data</OutputType>
</DataSourceModuleType>