Protected client discovery

Microsoft.Windows.SystemCenterDPM2010.ClientAutoDeployment.ProtectedClientDiscovery (Discovery)

Element properties:

TargetMicrosoft.Windows.SystemCenterDPM2010.ClientAutoDeployment.DPMServer
EnabledTrue
Frequency86400
RemotableFalse

Object Discovery Details:

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

Member Modules:

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

Source Code:

<Discovery ID="Microsoft.Windows.SystemCenterDPM2010.ClientAutoDeployment.ProtectedClientDiscovery" Enabled="true" Target="Microsoft.Windows.SystemCenterDPM2010.ClientAutoDeployment.DPMServer" ConfirmDelivery="true" Remotable="true" Priority="Normal">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="Microsoft.Windows.SystemCenterDPM2010.ClientAutoDeployment.DPMServer"/>
<DiscoveryClass TypeID="Microsoft.Windows.SystemCenterDPM2010.ClientAutoDeployment.ProtectedClient"/>
<DiscoveryRelationship TypeID="Microsoft.Windows.SystemCenterDPM2010.ClientAutoDeployment.DPMServerHostsProtectedClient"/>
</DiscoveryTypes>
<DataSource ID="ProtectedClientDiscovery" TypeID="Windows!Microsoft.Windows.TimedPowerShell.DiscoveryProvider">
<IntervalSeconds>86400</IntervalSeconds>
<SyncTime>00:00</SyncTime>
<ScriptName>ProtectedClientDiscovery.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);
}

$installPath = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Microsoft Data Protection Manager\Setup" | ForEach-Object {Get-ItemProperty $_.InstallPath}
$dpmInitScriptPath = $installPath.FullName + "bin\dpmcliinitscript.ps1"

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

$desc = "protected client discovery started"
DisplayError $desc 0 100 $null $null

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

#Connect to DPM server
$err = $($dpmServer = Connect-DPMServer -DPMServerName $dpmServerName) 2&gt;&amp;1
if (!$dpmServer)
{
$desc = "Protected client discovery - Unable to connect to DPM Server=" + $dpmServerName
if($err)
{
DisplayError $desc 1 101 $err.Exception.ToString() $err.Exception.Error.Resolution.ToString()
}
else
{
DisplayError $desc 1 101 $null $null
}

exit 1
}

#Get DPM auto deployment properties
$dpmVersion = $dpmServer.GetProductInformation().Version.ToString()
$isDPMIncludedForAutoDeployment = Get-DpmGlobalProperty -DPMServerName $dpmServerName -PropertyName ConsiderForAutoDeployment
$maxDPMCapacity = Get-DpmGlobalProperty -DPMServerName $dpmServerName -PropertyName MaxCapacityForClientAutoDeployment

$protectedClientCount = 0
$date = get-date
$utcDate = $date.ToUniversalTime()

#Get client PG list for the DPM server
$pgList = @(Get-ProtectionGroup -DPMServerName $dpmServerName | ?{$_.IsPGDisconnected})

foreach ($pg in $pgList)
{
if($pg)
{
#Get protected client datasources (primary datasources)
$dsList = @(Get-Datasource -ProtectionGroup $pg | ? {$_.Protected -and !$_.IsDPMDatasource})

foreach ($ds in $dsList)
{
if($ds)
{
#Retrieve the protected client name and corresponding PG name
$protectedClientName = $ds.ProductionServerName
$protectionGroupName = $pg.FriendlyName
$protectedBy = $dpmServerName
$protectedClientCount++
#write-host "ProtectedClient: $protectedClientName PGName: $protectionGroupName ProtectedBy: $protectedBy Clientcount: $protectedClientCount"

#Create a protected client instance
$clientinstance = $discoveryData.CreateClassInstance("$MPElement[Name="Microsoft.Windows.SystemCenterDPM2010.ClientAutoDeployment.ProtectedClient"]$")
$clientinstance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $dpmServerName)
$clientinstance.AddProperty("$MPElement[Name='Microsoft.Windows.SystemCenterDPM2010.ClientAutoDeployment.DPMServer']/DPMServerName$", $dpmServerName)
$clientinstance.AddProperty("$MPElement[Name='Microsoft.Windows.SystemCenterDPM2010.ClientAutoDeployment.ProtectedClient']/ProtectedClientName$", $protectedClientName)
$clientinstance.AddProperty("$MPElement[Name='Microsoft.Windows.SystemCenterDPM2010.ClientAutoDeployment.ProtectedClient']/ProtectedGroupName$", $protectionGroupName)
$clientinstance.AddProperty("$MPElement[Name='Microsoft.Windows.SystemCenterDPM2010.ClientAutoDeployment.ProtectedClient']/ProtectedBy$", $dpmServerName)
$discoveryData.AddInstance($clientinstance)
}
}
}
}

#Get the available capacity for the DPM server.
$availableCapacity = $maxDPMCapacity - $protectedClientCount
Disconnect-DPMServer $dpmServerName

#Update DPM properties
$instance = $discoveryData.CreateClassInstance("$MPElement[Name="Microsoft.Windows.SystemCenterDPM2010.ClientAutoDeployment.DPMServer"]$")
$instance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $dpmServerName)
$instance.AddProperty("$MPElement[Name='Microsoft.Windows.SystemCenterDPM2010.ClientAutoDeployment.DPMServer']/DPMServerName$", $dpmServerName)
$instance.AddProperty("$MPElement[Name="Microsoft.Windows.SystemCenterDPM2010.ClientAutoDeployment.DPMServer"]/DPMVersion$", $dpmVersion)
$instance.AddProperty("$MPElement[Name='Microsoft.Windows.SystemCenterDPM2010.ClientAutoDeployment.DPMServer']/ProtectedClientDiscoveryTime$", $utcDate.DateTime)
$instance.AddProperty("$MPElement[Name='Microsoft.Windows.SystemCenterDPM2010.ClientAutoDeployment.DPMServer']/AvailableCapacity$", $availableCapacity)
$instance.AddProperty("$MPElement[Name='Microsoft.Windows.SystemCenterDPM2010.ClientAutoDeployment.DPMServer']/IsIncluded$", $isDPMIncludedForAutoDeployment)
$discoveryData.AddInstance($instance)


$desc = "protected client discovery completed"
DisplayError $desc 0 102 $null $null

$discoveryData</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="Microsoft.Windows.SystemCenterDPM2010.ClientAutoDeployment.DPMServer"]/DPMServerName$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>7200</TimeoutSeconds>
</DataSource>
</Discovery>