<Discovery ID="Microsoft.Windows.SystemCenterDPM2010.DPMDataDiscovery" Enabled="true" Target="Microsoft.Windows.SystemCenterDPM2010.DPMServer" ConfirmDelivery="false" Remotable="false" Priority="Normal">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="Microsoft.Windows.SystemCenterDPM2010.ProductionServer">
<Property TypeID="Microsoft.Windows.SystemCenterDPM2010.ProductionServer" PropertyID="ServerNameLong"/>
</DiscoveryClass>
<DiscoveryClass TypeID="Microsoft.Windows.SystemCenterDPM2010.DataSource">
<Property TypeID="Microsoft.Windows.SystemCenterDPM2010.DataSource" PropertyID="DataSourceId"/>
</DiscoveryClass>
<DiscoveryClass TypeID="Microsoft.Windows.SystemCenterDPM2010.Disk">
<Property TypeID="Microsoft.Windows.SystemCenterDPM2010.Disk" PropertyID="DiskId"/>
</DiscoveryClass>
<DiscoveryClass TypeID="Microsoft.Windows.SystemCenterDPM2010.Library">
<Property TypeID="Microsoft.Windows.SystemCenterDPM2010.Library" PropertyID="LibraryId"/>
</DiscoveryClass>
<DiscoveryClass TypeID="Microsoft.Windows.SystemCenterDPM2010.Drive">
<Property TypeID="Microsoft.Windows.SystemCenterDPM2010.Drive" PropertyID="DriveId"/>
</DiscoveryClass>
</DiscoveryTypes>
<DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedScript.DiscoveryProvider">
<IntervalSeconds>43200</IntervalSeconds>
<SyncTime/>
<ScriptName>DPMDataDiscovery.vbs</ScriptName>
<Arguments>0 $MPElement$ $Target/Id$ $Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$</Arguments>
<ScriptBody><Script>'*****************************************************************************
' Author - SatyaY
' Date - 24 December 2007
' Purpose - Script to get the DPM Server data - PS, DS, Disk and Library
'*****************************************************************************
SetLocale("en-us")
Set oAPI = CreateObject("MOM.ScriptAPI")
Set oArgs = WScript.Arguments
if oArgs.Count < 4 Then
call oAPI.LogScriptEvent("DPMDataDiscovery", 12, 1, "Expected 4 arguments. There were only " & oArgs.Count & " arguments. Exiting script.")
Wscript.Quit -1
End If
Set oDiscData = oAPI.CreateDiscoveryData(SourceType, SourceId, ManagedEntityId)
'************************************************
' Creating temporary PS file to generate the data
'************************************************
Dim objShell
Set objShell=CreateObject("WScript.Shell")
'enter the PowerShell expression
'you need to use short filenames and paths
' Create the File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Check that the strDirectory folder exists
If objFSO.FolderExists(strDirectory) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFolder = objFSO.CreateFolder(strDirectory)
End If
If objFSO.FileExists(strDirectory & strFile) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFile = objFSO.CreateTextFile(strDirectory & strFile)
End If
'***************************************************
' Get DPM install path to launch the powershell
'***************************************************
Dim dpmShellPath
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
dpmShellPath = """" & strValue & "bin\dpmshell.psc1" & """"
'MsgBox "The DPM InstallPath is: " & strValue
'*********************************************************
' Generating the ps1 file to get the data from powershell
'**********************************************************
set objFile = Nothing
set objFolder = Nothing
strText="$xmlfilepath = """ + strDirectory + """" &_
Chr(10) & "$dpmServerName = $env:computername " &_
Chr(10) & "$dpmServer = Connect-DPMServer $dpmServerName " &_
Chr(10) & "if (!$dpmServer) " &_
Chr(10) & "{ " &_
Chr(10) & " Write-Error ""Unable to connect to $dpmServerName"" " &_
Chr(10) & " exit 1 " &_
Chr(10) & "} " &_
Chr(10) & "$dpmversion = $dpmServer.GetProductInformation().Version.ToString() " &_
Chr(10) & "$pslist = @(get-productionserver -dpmservername $dpmServerName | ?{$_.ServerProtectionState -ine ""Deleted"" -and !$_.IsProtectedInDisconnectedPG}) " &_
Chr(10) & "$liblist = Get-DPMLibrary -dpmservername $dpmServerName | ?{!$_.IsOffline -or $_.ProtectionGroups -ine """" } " &_
Chr(10) & "$disklist = Get-DPMDisk -dpmservername $dpmServerName | ?{$_.IsInStoragePool}" &_
Chr(10) & "$xml = ""<DPM PrincipalName=""""$($dpmServer.Name)"""" " &_
Chr(10) & " NetbiosDomainName=""""$($dpmServer.Domain)"""" " &_
Chr(10) & " NetbiosComputerName=""""$($dpmServerName)"""" " &_
Chr(10) & " DPMVersion=""""$($dpmversion)"""" " &_
Chr(10) & " ProductionServerCount=""""$($pslist.count)"""">`n"" " &_
Chr(10) & "$xml += ""<PSList>`n"" " &_
Chr(10) & "foreach ($ps in $pslist) " &_
Chr(10) & "{ " &_
Chr(10) & " if($ps) "&_
Chr(10) & "{ "&_
Chr(10) & " $dslist = @(Get-Datasource -productionserver $ps | ? {$_.Protected}) " &_
Chr(10) & " $xml += ""<PS DisplayName=""""$($ps.MachineName)"""" " &_
Chr(10) & " ServerNameLong=""""$($ps.Name)"""" " &_
Chr(10) & " DomainName=""""$($ps.DomainName)"""" " &_
Chr(10) & " ClusterName=""""$($ps.ClusterName)"""" " &_
Chr(10) & " ProtectedBy=""""$($dpmServer.Name)"""" " &_
Chr(10) & " ProtectedViaDC=""""$($ps.IsProtectedViaDC)"""" " &_
Chr(10) & " DataSourceCount=""""$($dslist.count)"""" >`n"" " &_
Chr(10) & " $xml += ""<DSList>`n"" " &_
Chr(10) & " if($dslist) " &_
Chr(10) & " { " &_
Chr(10) & " foreach($ds in $dslist) " &_
Chr(10) & " { " &_
Chr(10) & " if($ds) "&_
Chr(10) & " { "&_
Chr(10) & " $pg = Get-ProtectionGroup $dpmServerName | ?{$_.Protectiongroupid -eq $ds.ProtectionGroupId} "&_
Chr(10) & " $xml += ""<DS FullServerName=""""$($ds.ProductionServerName)"""" " &_
Chr(10) & " DisplayName=""""$($ps.MachineName)"""" " &_
Chr(10) & " ProtectedBy=""""$($dpmServer.Name)"""" " &_
Chr(10) & " ProtectionGroup=""""$($ds.ProtectionGroupName)"""" " &_
Chr(10) & " DataSourceType=""""$($ds.ToString(""""T"""", $null))"""" " &_
Chr(10) & " DataSourceName=""""$($ds.Name)"""" " &_
Chr(10) & " IsDPMDataSource=""""$($ds.IsDPMDatasource)"""" " &_
Chr(10) & " DataSourceId=""""$($ds.DatasourceId.ToString())"""" />`n"" " &_
Chr(10) &" }"&_
Chr(10) & " } " &_
Chr(10) & " } " &_
Chr(10) & " $xml += ""</DSList>`n"" " &_
Chr(10) & " $xml += ""</PS>`n"" " &_
Chr(10) & "} "&_
Chr(10) & "} " &_
Chr(10) & "$xml += ""</PSList>`n"" " &_
Chr(10) & "$xml += ""<DiskList>`n"" " &_
Chr(10) & "foreach ($disk in $disklist) " &_
Chr(10) & "{ " &_
Chr(10) & " if($disk) "&_
Chr(10) & "{ "&_
Chr(10) & " $allocated = $disk.TotalCapacity - $disk.UnallocatedSpace " &_
Chr(10) & " $percentallocated = ""{0:F2}"" -f (100 * $allocated / $disk.TotalCapacity) " &_
Chr(10) & " $dispName = ""Disk"" + $disk.NtDiskID + ""("" + $disk.Name + "")"" " &_
Chr(10) & " $percentunallocated = ""{0:F2}"" -f (100 - $percentallocated) " &_
Chr(10) & " $allocated = ""{0:F2}"" -f ($allocated / (1024 * 1024 * 1024)) " &_
Chr(10) & " $allocated = [system.string]$allocated + "" GB"" " &_
Chr(10) & " $Unallocated = ""{0:F2}"" -f ($disk.UnallocatedSpace / (1024 * 1024 * 1024)) " &_
Chr(10) & " $Unallocated = [system.string]$Unallocated + "" GB"" " &_
Chr(10) & " $disksize = ""{0:F2}"" -f ($disk.TotalCapacity / (1024 * 1024 * 1024)) " &_
Chr(10) & " $disksize = [system.string]$disksize + "" GB"" " &_
Chr(10) & " $xml += ""<Disk DiskId=""""$($disk.Identifier.ToString())"""" " &_
Chr(10) & " DiskName=""""$($disk.Name)"""" " &_
Chr(10) & " DiskType=""""$($disk.GetType().Name)"""" " &_
Chr(10) & " DPMServerName=""""$($disk.DPMServerName)"""" " &_
Chr(10) & " DiskSize=""""$($disksize)"""" " &_
Chr(10) & " UnallocatedSize=""""$($Unallocated)"""" " &_
Chr(10) & " AllocatedSize=""""$($allocated)"""" " &_
Chr(10) & " PercentAllocated=""""$($percentallocated)"""" " &_
Chr(10) & " DisplayName=""""$($dispName)"""" " &_
Chr(10) & " PercentUnallocated=""""$($percentunallocated)"""" />`n"" " &_
Chr(10) & "} "&_
Chr(10) & "} " &_
Chr(10) & "$xml += ""</DiskList>`n"" " &_
Chr(10) & "$xml += ""<LibList>`n"" " &_
Chr(10) & "foreach ($lib in $liblist) " &_
Chr(10) & "{ " &_
Chr(10) & " if($lib) "&_
Chr(10) & "{ "&_
Chr(10) & " $drivelist = $lib.GetDriveCollection() " &_
Chr(10) & " $mediacollection = $lib.GetMediaCollection() " &_
Chr(10) & " $tapeDriveCount = 0 " &_
Chr(10) & " $tapeslots = 0 " &_
Chr(10) & " foreach($media in $mediacollection) " &_
Chr(10) & " { " &_
Chr(10) & " if($media.Location.Name -eq ""Drive"") " &_
Chr(10) & " { " &_
Chr(10) & " $tapeDriveCount++ " &_
Chr(10) & " } elseif($media.Location.Name -ieq ""slot"") " &_
Chr(10) & " { " &_
Chr(10) & " $tapeslots++ " &_
Chr(10) & " } " &_
Chr(10) & " } " &_
Chr(10) & " $slotsCount = $lib.GetSlotCollection().Count " &_
Chr(10) & " $freeslots = $slotsCount - $tapeslots " &_
Chr(10) & " $freedrives = $lib.GetDriveCollection().Count - $tapeDriveCount " &_
Chr(10) & " $xml += ""<Lib LibraryId=""""$($lib.Id.ToString())"""" " &_
Chr(10) & " LibraryType=""""$($lib.Type)"""" " &_
Chr(10) & " DPMServerName=""""$($lib.MachineName)"""" " &_
Chr(10) & " SlotsCount=""""$($slotsCount)"""" " &_
Chr(10) & " TapesCount=""""$($mediacollection.Count)"""" " &_
Chr(10) & " DriveCount=""""$($drivelist.Count)"""" " &_
Chr(10) & " FreeSlotsCount=""""$($freeslots)"""" " &_
Chr(10) & " TapeSlotsCount=""""$($tapeslots)"""" " &_
Chr(10) & " FreeDriveCount=""""$($freedrives)"""" " &_
Chr(10) & " DisplayName=""""$($lib.UserFriendlyName)"""" >`n"" " &_
Chr(10) & " $xml += ""<DriveList>`n"" " &_
Chr(10) & " if($drivelist) " &_
Chr(10) & " { " &_
Chr(10) & " foreach($drive in $drivelist) " &_
Chr(10) & " { " &_
Chr(10) & " if($drive) "&_
Chr(10) & " { "&_
Chr(10) & " $scsiid = ""Port:"" + $drive.SCSIPort + "" Bus:"" + $drive.SCSIBus + "" Target:"" + $drive.SCSITargetId + "" Lun:"" + $drive.SCSILun "&_
Chr(10) & " $readerrors = ""Critical:"" + $drive.HardReadErrors + ""|"" + ""Transient:"" + $drive.SoftReadErrors "&_
Chr(10) & " $writeerrors = ""Critical:"" + $drive.HardWriteErrors + ""|"" + ""Transient:"" + $drive.SoftWriteErrors "&_
Chr(10) & " $xml += ""<Drive DriveId=""""$($drive.Id.ToString())"""" " &_
Chr(10) & " DriveName=""""$($drive.ProductId)"""" " &_
Chr(10) & " DriveStatus=""""$($drive.Status)"""" " &_
Chr(10) & " LibraryName=""""$($drive.LibraryName)"""" " &_
Chr(10) & " DPMServerName=""""$($dpmServerName)"""" " &_
Chr(10) & " DriveSerialNumber=""""$($drive.SerialNumber)"""" " &_
Chr(10) & " DriveType=""""$($drive.MediaTypesSupported)"""" " &_
Chr(10) & " WindowsDriveName=""""$($drive.AccessPath)"""" " &_
Chr(10) & " SCSIID=""""$($scsiid)"""" " &_
Chr(10) & " LastCleaned=""""$($drive.LastCleaningDate.ToString())"""" " &_
Chr(10) & " ReadErrorsSinceLastCleaned=""""$($readerrors)"""" " &_
Chr(10) & " WriteErrorsSinceLastCleaned=""""$($writeerrors)"""" />`n"" " &_
Chr(10) & " }"&_
Chr(10) & " } " &_
Chr(10) & " } " &_
Chr(10) & " $xml += ""</DriveList>`n"" " &_
Chr(10) & " $xml += ""</Lib>`n"" " &_
Chr(10) & " }" &_
Chr(10) & "} " &_
Chr(10) & "Disconnect-DPMServer " &_
Chr(10) & "$xml += ""</LibList>`n"" " &_
Chr(10) & "$xml += ""</DPM>`n"" " &_
Chr(10) & "$xmlfile = [xml] $xml " &_
Chr(10) & "$xmlfile.save((Join-path $xmlfilepath ""DPMDiscoveryData.xml""))"
Set objTextFile = objFSO.OpenTextFile _
(strDirectory & strFile, ForWriting, True)
' Writes strText every time you run this VBScript
objTextFile.WriteLine(strText)
objTextFile.Close
psfile = strDirectory & strFile
strCMD="powershell -PSConsoleFile " & dpmShellPath & " -nologo -command " & psfile
'Uncomment next line for debugging
'MsgBox("strCMD: " & strCMD)
'use 0 to hide window
objShell.Run strCMD,0,true
'***********************************************************************************
' Reading the xml file generated from PS script and creating the MOM objects
'***********************************************************************************
set xmlDoc=CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load(strDirectory & "\DPMDiscoveryData.xml")
Set root = xmlDoc.documentElement
Set oDPMInst = oDiscData.CreateClassInstance("$MPElement[Name="Microsoft.Windows.SystemCenterDPM2010.DPMServer"]$")