Zjišťování svazku repliky a disku

Microsoft.SystemCenter.DataProtectionManager.2011.Discovery.VolumeAndDiskDiscovery (Discovery)

Element properties:

TargetMicrosoft.SystemCenter.DataProtectionManager.2011.Library.DPMServer
EnabledTrue
Frequency43200
RemotableFalse

Object Discovery Details:

Discovered Classes and their attribuets:
Discovered relationships and their attribuets:

Member Modules:

ID Module Type TypeId RunAs 
VolumeAndDiskDiscovery DataSource Microsoft.Windows.TimedPowerShell.DiscoveryProvider Default

Source Code:

<Discovery ID="Microsoft.SystemCenter.DataProtectionManager.2011.Discovery.VolumeAndDiskDiscovery" Enabled="true" Target="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMServer" ConfirmDelivery="true" Remotable="true" Priority="Normal">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.ReplicaVolume"/>
<DiscoveryClass TypeID="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMDisk"/>
<DiscoveryRelationship TypeID="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMServerHostsDisk"/>
<DiscoveryRelationship TypeID="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMServerHostsReplicaVolume"/>
</DiscoveryTypes>
<DataSource ID="VolumeAndDiskDiscovery" TypeID="Windows!Microsoft.Windows.TimedPowerShell.DiscoveryProvider">
<IntervalSeconds>43200</IntervalSeconds>
<SyncTime/>
<ScriptName>VolumeAndDiskDiscovery.ps1</ScriptName>
<ScriptBody><Script>#Read input parameters
param($sourceType,$sourceId,$managedEntityId,$dpmServerName)

function DisplayError()
{
param($description, $severity, $errorCode, $exceptionString, $resolutionString)

$evt = new-object System.Diagnostics.EventLog("DPM Alerts");
$evt.Source = "DPM-EM";
$eventSeverity = [System.Diagnostics.EventLogEntryType]::Information;

#severity = 0 is info and severity = 1 is warning
if($severity -eq 1)
{
$eventSeverity = [System.Diagnostics.EventLogEntryType]::Warning;
}

$errString = new-object system.text.stringBuilder
$errString.AppendLine($description)

if($exceptionString -ne $null)
{
$errString.AppendLine()
$errString.AppendLine("Problem: " + $exceptionString)
}

if($resolutionString -ne $null)
{
$errString.AppendLine()
$errString.AppendLine("Resolution: " + $resolutionString)
}

$evt.WriteEntry($errString.ToString(), $eventSeverity, $errorCode);
}


$desc = "Volume and disk discovery start event for dpmServerName =" + $dpmServerName
DisplayError $desc 0 116 $null $null

# Load DPM snapin
$dpmBinPath = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Microsoft Data Protection Manager\Setup" "UIInstallPath").UIInstallPath
. "$dpmBinPath\GlobalFunctions.ps1"
LoadDPMSnapin

#Create and Instantinate SCOM discovery objects
$api = New-Object -comObject 'MOM.ScriptAPI'
$discoveryData = $api.CreateDiscoveryData($sourceType, $sourceId, $managedEntityId)

try
{
#Connect to DPM server
$err = $($dpmServer = Connect-DPMServer $dpmServerName) 2&gt;&amp;1
if (!$dpmServer)
{
$desc = "Volume and disk discovery - Unable to connect to DPM server: dpmServerName =" + $dpmServerName
if($err)
{
DisplayError $desc 1 117 $err.Exception.ToString() $err.Exception.Error.Resolution.ToString()
}
else
{
DisplayError $desc 1 117 $null $null
}

exit 1
}


#Get disk list for the DPM server
$err = $($diskList = @(Get-DPMDisk -DPMServerName $dpmServerName | where {$_.IsInStoragePool -eq $true}) ) 2&gt;&amp;1
if($err)
{
$desc = "Unable to retrieve disk list"
DisplayError $desc 1 117 $err.Exception.ToString() $err.Exception.Error.Resolution.ToString()
}

if($diskList)
{
$diskList = $diskList | Sort-Object $_.Name
}

foreach ($disk in $diskList)
{
if($disk)
{
$totalSpace = "{0:F0}" -f ($disk.TotalCapacity/(1024 * 1024 * 1024))
$freeSpace = "{0:F0}" -f ($disk.UnallocatedSpace/(1024 * 1024 * 1024))

#Create a disk instance
$diskInstance = $discoveryData.CreateClassInstance("$MPElement[Name="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMDisk"]$")
$diskInstance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $dpmServerName)
$diskInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMSeed']/DPMServerName$", $dpmServerName)
$diskInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMServer']/DPMServerName$", $dpmServerName)
$diskInstance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", $disk.Name)
$diskInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMDisk']/DPMServerName$", $dpmServerName)
$diskInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMDisk']/DPMObjectID$", $disk.Identifier.ToString())
$diskInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMDisk']/TotalSpace$", $totalSpace)
$diskInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMDisk']/FreeSpace$", $freeSpace)
$discoveryData.AddInstance($diskInstance)

Remove-Variable diskInstance -Confirm:$false
}
}

#Get ReFS volume list for the DPM server
if (Get-Command Get-DPMDiskStorage -ErrorAction SilentlyContinue)
{
$err = $($refsVolList = @(Get-DPMDiskStorage -DPMServerName $dpmServerName -Volumes) ) 2&gt;&amp;1
if($err)
{
$desc = "Unable to retrieve ReFS volume list"
DisplayError $desc 1 117 $err.Exception.ToString() $err.Exception.Error.Resolution.ToString()
}

if($refsVolList)
{
$refsVolList = @($refsVolList | Sort-Object $_.AccessPath)
}

foreach ($disk in $refsVolList)
{
if($disk)
{
$totalSpace = "{0:F0}" -f ($disk.TotalSpace/(1024 * 1024 * 1024))
$freeSpace = "{0:F0}" -f (($disk.TotalSpace - $disk.OptimizedUsedSpace)/(1024 * 1024 * 1024))

#Create a disk instance
$diskInstance = $discoveryData.CreateClassInstance("$MPElement[Name="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMDisk"]$")
$diskInstance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $dpmServerName)
$diskInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMSeed']/DPMServerName$", $dpmServerName)
$diskInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMServer']/DPMServerName$", $dpmServerName)
$diskInstance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", $disk.AccessPath)
$diskInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMDisk']/DPMServerName$", $dpmServerName)
$diskInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMDisk']/DPMObjectID$", $disk.StorageId.ToString())
$diskInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMDisk']/TotalSpace$", $totalSpace)
$diskInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMDisk']/FreeSpace$", $freeSpace)
$discoveryData.AddInstance($diskInstance)

Remove-Variable diskInstance -Confirm:$false
}
}
}

#Get volume list for the DPM server
$err = $($volumeList = Get-DPMVolume -DPMServerName $dpmServerName -AlreadyInUseByDPM | ?{$_.VolumeType -eq [Microsoft.Internal.EnterpriseStorage.Dls.StoragePoolManager.EnumUsage]::Replica}) 2&gt;&amp;1

if($err)
{
$desc = "Unable to retrieve volume list"
DisplayError $desc 1 117 $err.Exception.ToString() $err.Exception.Error.Resolution.ToString()
}

if($volumeList)
{
$volumeList = $volumeList | Sort-Object $_.VolumeSetId
}

foreach ($volume in $volumeList)
{
if($volume)
{
$volumeInstance = $discoveryData.CreateClassInstance("$MPElement[Name="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.ReplicaVolume"]$")
$volumeInstance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $dpmServerName)
$volumeInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMSeed']/DPMServerName$", $dpmServerName)
$volumeInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMServer']/DPMServerName$", $dpmServerName)
$volumeInstance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", $volume.ToString())
$volumeInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.ReplicaVolume']/DPMServerName$", $dpmServerName)
$volumeInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.ReplicaVolume']/DPMObjectID$", $volume.VolumeSetId.ToString())
$discoveryData.AddInstance($volumeInstance)

Remove-Variable volumeInstance -Confirm:$false
}
}

#Get the list of data sources protected using MDS from the DPM server
if (Get-Command Get-DPMDiskStorage -ErrorAction SilentlyContinue)
{
$err = $($dsList = Get-DPMDatasource -DPMServerName $dpmServerName | Where{($_.ProtectionGroupId -ne [Guid]::Empty) -and ($_.ProtectionGroup -ne $null) -and ($_.ProtectionGroup.IsDiskShortTerm) -and (-not $_.ProtectionGroup.UsesLegacyStorageStack)}) 2&gt;&amp;1

if($err)
{
$desc = "Unable to retrieve data sources protected using modern storage stack"
DisplayError $desc 1 117 $err.Exception.ToString() $err.Exception.Error.Resolution.ToString()
}

foreach ($ds in $dsList)
{
if($ds)
{
$volumeId = $ds.AssociatedReplica.PhysicalReplicaId.ToString()
$volumeInstance = $discoveryData.CreateClassInstance("$MPElement[Name="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.ReplicaVolume"]$")
$volumeInstance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $dpmServerName)
$volumeInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMSeed']/DPMServerName$", $dpmServerName)
$volumeInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMServer']/DPMServerName$", $dpmServerName)
$volumeInstance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", $volumeId)
$volumeInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.ReplicaVolume']/DPMServerName$", $dpmServerName)
$volumeInstance.AddProperty("$MPElement[Name='SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.ReplicaVolume']/DPMObjectID$", $volumeId)
$discoveryData.AddInstance($volumeInstance)

Remove-Variable volumeInstance -Confirm:$false
}
}
}

}
catch
{
$desc = "Exception in volume and disk discovery"
DisplayError $desc 1 117 $_.ToString() $null
throw $_
}

$desc = "Volume and disk discovery completed for dpmServerName =" + $dpmServerName
DisplayError $desc 0 118 $null $null

$discoveryData

#Cleanup Variables
Remove-Variable sourceType -Confirm:$false
Remove-Variable sourceId -Confirm:$false
Remove-Variable managedEntityId -Confirm:$false
Remove-Variable discoveryData -Confirm:$false
Remove-Variable api -Confirm:$false
</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>SourceType</Name>
<Value>0</Value>
</Parameter>
<Parameter>
<Name>SourceId</Name>
<Value>$MPElement$</Value>
</Parameter>
<Parameter>
<Name>ManagedEntityId</Name>
<Value>$Target/Id$</Value>
</Parameter>
<Parameter>
<Name>DPMServerName</Name>
<Value>$Target/Property[Type="SCDPM!Microsoft.SystemCenter.DataProtectionManager.2011.Library.DPMServer"]/DPMServerName$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>7200</TimeoutSeconds>
</DataSource>
</Discovery>