ディスク パーティションと論理ディスクの検出モジュール

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

Windows サーバー上のディスク パーティションと論理ディスク間の関係を検出

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
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.DiskPartitionContainsLogicalDiskDiscovery.ModuleType" 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="DeviceID" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="IntervalSeconds" type="xsd:integer"/>
<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>DiskPartitionContainsLogicalDisk.ps1</ScriptName>
<PSparam>param ($SourceID, $ManagedEntityId, $TargetComputer, $TargetComputerID, $DeviceID)</PSparam>
<ScriptBody><Script>Function Add-LogicalDiskToPartition([string]$PartitionId,[string]$LogicalDiskPerfId,[HashTable]$PartToLogicalDisk)
{
if ([string]::IsNullOrEmpty($PartitionId) -or [string]::IsNullOrEmpty($LogicalDiskPerfId) )
{
return
}

$PartToLogicalDisk[$PartitionId] = $LogicalDiskPerfId
}

Function Add-DiskToPartition([string]$PartitionId,[string]$DiskId,[HashTable]$DiskToPartition)
{

if ([string]::IsNullOrEmpty($PartitionId) -or [string]::IsNullOrEmpty($DiskId) -or $null -eq $DiskToPartition)
{
return
}

$Partitions = $DiskToPartition[$DiskId]

if ($null -eq $Partitions)
{
$Partitions = @()
}

$Partitions += $PartitionId

$DiskToPartition[$DiskId] = $Partitions
}

Function Get-PerfInstancePostFix($oSet,[HashTable]$PartToLogicalDisk,[bool]$IsSet = $true)
{
$PerfPostFix = [string]::Empty
$iCount = $oSet.Count

if (0 -eq $iCount -or $null -eq $oSet)
{
return $PerfPostFix
}

if ($null -eq $iCount)
{
$iCount = 1
}

$PerfInstance = @(1..$iCount)
$Index = 0

foreach ($owObj in $oSet)
{
if ($true -eq $IsSet)
{
$PartitionId = $owObj.DeviceID
}
else
{
$PartitionId = $owObj
}

if ([string]::IsNullOrEmpty($PartitionId))
{
continue
}
$PerfPostFix = $PartToLogicalDisk[$PartitionId]
if($null -ne $PerfPostFix)
{
$PerfInstance[$Index] = $PerfPostFix
$Index++
}

}

if (0 -ne $Index)
{
for ($i = $Index;$i -lt $iCount; $i++)
{
$PerfInstance[$i] = [string]::Empty
}

$PerfPostFix = [string]::Join(" ",$PerfInstance).Trim(" ")
}

return $PerfPostFix
}

Function Get-PartitionToLogicalDiskTable($sTargetComputer)
{
$PartToLogicalDisk = @{}
$oWMISet= WMIGetInstanceNoAbort $sTargetComputer "root\cimv2" $WMI_Partition_To_LogicalDisk

foreach ($owObj in $oWMISet)
{
$PartitionId = $owObj.Antecedent.DeviceId
$LogicalDiskPerfId = $owObj.Dependent.DeviceId

Add-LogicalDiskToPartition -PartitionId $PartitionId -LogicalDiskPerfId $LogicalDiskPerfId -PartToLogicalDisk $PartToLogicalDisk

}

return $PartToLogicalDisk
}

Function Get-DiskToPartitionTable($sTargetComputer)
{

$DiskToPartition = @{}
$oWMISet= WMIGetInstanceNoAbort $sTargetComputer "root\cimv2" $WMI_DISk_To_Partition

foreach ($owObj in $oWMISet)
{
$DiskId = $owObj.Antecedent.DeviceId
$PartitionId = $owObj.Dependent.DeviceId

Add-DiskToPartition -PartitionId $PartitionId -DiskId $DiskId -DiskToPartition $DiskToPartition

}

return $DiskToPartition
}

Function Get-DiskToPartitionPerfInstance($sTargetComputer)
{

$DiskToPerfInstance = @{}
$PartToLogicalDisk = Get-PartitionToLogicalDiskTable -sTargetComputer $sTargetComputer
$DiskToPartitionTable = Get-DiskToPartitionTable -sTargetComputer $sTargetComputer
foreach ($DiskId in $DiskToPartitionTable.Keys)
{
$sPerfInstance = [string]::Empty
$oSet = $DiskToPartitionTable[$DiskId]

$PerfInstancePostfix = Get-PerfInstancePostFix -oSet $oSet -PartToLogicalDisk $PartToLogicalDisk -IsSet $false

if (-Not [string]::IsNullOrEmpty($PerfInstancePostfix))
{
$sPerfInstance += $PerfInstancePostfix
}

$DiskToPerfInstance[$DiskId] = $sPerfInstance
}

return $DiskToPerfInstance
}

Function Get-LogicalDiskSerialNmber([string]$TargetComputer,[string]$LogicalDiskId)
{
if ([string]::IsNullOrEmpty($LogicalDiskId) )
{
return [string]::Empty
}

$Query = "Select VolumeSerialNumber From Win32_LogicalDisk Where DeviceID='$LogicalDiskId'"
$oInstances = WMIExecQueryNoAbort $sTargetComputer "root\cimv2" $Query

$SerialNumber = [string]::Empty
if (0 -ne $oInstances.Count )
{
$SerialNumber = $oInstances[0].VolumeSerialNumber
if($null -eq $SerialNumber)
{
$SerialNumber = [string]::Empty
}
}

return $SerialNumber
}

Function GetHddPerfmonInstance
{
param ( [string]$DriveId, [string]$Index,[HashTable]$DiskPerfInstance)

$sPerfInstance = "$Index "

$PerfInstancePostfix = $DiskPerfInstance[$DriveId]
if (-Not [string]::IsNullOrEmpty($PerfInstancePostfix))
{
$sPerfInstance += $PerfInstancePostfix
}

return $sPerfInstance
}
Function Main()
{
$objWMIColl = $null

$IsCluster = CheckCluster $TargetComputer

if ($IsCluster -eq $true)
{
$objWMIColl = GetClusterDiskCollection $TargetComputer
}

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

if ((DoDiscovery $TargetComputer $TargetComputerID $oDiscoveryData $IsCluster $objWMIColl $DeviceID) -eq 0)
{
$oDiscoveryData
}
else
{
$oDiscoveryData = $momAPI.CreateDiscoveryData(0, $SourceID, $ManagedEntityId)
$oDiscoveryData.IsSnapshot = $false
}
}

Function DoDiscovery
{
param ([string]$sTargetComputer, [string]$sTargetComputerID, $oDisc, [bool]$IsCluster, $objWMIColl, $sDeviceID)

if ([string]::IsNullOrEmpty($sDeviceID) )
{
return 0
}

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

$PartToLogicalDisk = Get-PartitionToLogicalDiskTable -sTargetComputer $sTargetComputer
if (0 -ne $error.Count)
{
return $error.Count
}

$LogicalDiskId = $PartToLogicalDisk[$sDeviceID]

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

if([string]::IsNullOrEmpty($LogicalDiskId))
{
return 0
}

$LogicalDiskSerialNumber = Get-LogicalDiskSerialNmber -TargetComputer $sTargetComputer -LogicalDiskId $LogicalDiskId

#Cannot get Logical disk Serial Number. So cannot check for Cluster Disk
if([string]::IsNullOrEmpty($LogicalDiskSerialNumber) -and $true -eq $IsCluster)
{
return 1
}

$IsClusterDisk = CheckIsClusterDisk $LogicalDiskId $LogicalDiskSerialNumber $IsCluster $objWMIColl

if ($true -eq $IsClusterDisk)
{
return 0
}

$error.Clear()


$oInstancePartition = $oDisc.CreateClassInstance("$MPElement[Name='Microsoft.Windows.Server.10.0.DiskPartition']$")
$oInstancePartition.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $sTargetComputerID)
$oInstancePartition.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.LogicalDevice']/DeviceID$", $sDeviceID)

$oInstanceLogicalDisk = $oDisc.CreateClassInstance("$MPElement[Name='Microsoft.Windows.Server.10.0.LogicalDisk']$")
$oInstanceLogicalDisk.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $sTargetComputerID)
$oInstanceLogicalDisk.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.LogicalDevice']/DeviceID$", $LogicalDiskId)

$oInstanceRelationship = $oDisc.CreateRelationshipInstance("$MPElement[Name='Microsoft.Windows.Server.10.0.DiskPartitionContainsLogicalDisk']$")
$oInstanceRelationship.source = $oInstancePartition
$oInstanceRelationship.target = $oInstanceLogicalDisk

$oDisc.AddInstance($oInstanceRelationship)


return $error.Count
}


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>
<Parameter>
<Name>DeviceID</Name>
<Value>$Config/DeviceID$</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>