Issues: Seen many blogs/examples on returning data but none
align...($scomapi.Return($DiscData) or $DiscData). Any key properties of
class or parent classes must be populated. Have noticed my eventlog
statements are only created once per DB, seems to indicate something passed
thru is wrong but can't tell what...
Overview: Custom Class hosted by Exchange Mailbox Databases to discover
individual mailboxes. Created PS Script Discovery Provider Module as Data
Source for custom discovery.
Class-
- <ClassType ID="XOM.Exchange.Custom.MailboxClass" Accessibility="Internal"
Abstract="false"
Base="MicrosoftExchangeServer2007Library6064890!Microsoft.Exchange2007.Component.Database.PrivateMdb" Hosted="true" Singleton="false">
<Property ID="Name" Type="string" Key="false" CaseSensitive="false"
Length="256" MinLength="0" />
<Property ID="LastLogonTime" Type="string" Key="false"
CaseSensitive="false" Length="256" MinLength="0" />
</ClassType>
Data Source-
<Configuration p1:noNamespaceSchemaLocation="C:\Documents and
Settings\nwelch.NA\Local Settings\Temp\1\DS - PowerShell Script Discovery
Provider.xsd" xmlns:p1="http://www.w3.org/2001/XMLSchema-instance">
<IntervalSeconds>$Config/InternalSec$</IntervalSeconds>
<SyncTime>00:00</SyncTime>
<ScriptName>GetMailbox.ps1 $MPElement$ $Target/Id$
$config/DBname$</ScriptName>
<ScriptBody>
write-host "Script started."
param($Element,$Target,$Identity)
#$Target = $args[1]
#$Element = $args[0]
#$Identity = $Args[2]
#Interactive Debug Statement
write-host $Target, $Element, $Identity
#Event Log (OpsMgr) Debug Statement
if ($Identity -eq $NULL) {$scomapi.logscriptevent("Mailbox Discovery
Test",100,0,"Identity is NULL")}
$scomapi = new-object -comObject 'MOM.ScriptAPI'
#Event Log (OpsMgr) Debug Statement
$scomapi.logscriptevent("Mailbox Discovery Test",100,0,"In script")
#Create discovery "bag"
$DiscData = $scomapi.CreateDiscoveryData(0, $Element, $Target)
#Get list of mailboxes on the db with all properties
$list = Get-MailboxStatistics -database $Identity
#Event Log (OpsMgr) Debug Statement
$scomapi.logscriptevent("Mailbox Discovery Test",100,0,"Got list")
foreach ($i in $list)
{$Instance =
$DiscData.CreateClassInstance("$MPElement[Name='XOM.Exchange.Custom.MailboxClass']$")
$instance.AddProperty("$MPElement[Name='MicrosoftExchangeServer2007Library6064890!Microsoft.Exchange2007.Component.Database']/Identity$", $Identity)
$Instance.AddProperty("$MPElement[Name='XOM.Exchange.Custom.MailboxClass']/Name$", $i.DisplayName)
$Instance.AddProperty("$MPElement[Name='XOM.Exchange.Custom.MailboxClass']/LastLogonTime$", $i.LastLogonTime)
$DiscData.AddInstance($Instance)
#Event Log (OpsMgr) Debug Statement
$scomapi.logscriptevent("Mailbox Discovery Test",100,0,"End of instance")
}
#Two tries?
$scomapi.Return($DiscData)
$DiscData
</ScriptBody>
<TimeoutSeconds>$Config/TimeoutSec$</TimeoutSeconds>
</Configuration>
Discovery -
- <Discovery ID="XOM.Exchange.Custom.DiscoverMailboxes" Enabled="true"
Target="MicrosoftExchangeServer2007Library6064890!Microsoft.Exchange2007.Component.Database.PrivateMdb"
ConfirmDelivery="true" Remotable="true" Priority="Normal">
<Category>Discovery</Category>
- <DiscoveryTypes>
- <DiscoveryClass TypeID="XOM.Exchange.Custom.MailboxClass">
<Property TypeID="XOM.Exchange.Custom.MailboxClass" PropertyID="Name" />
<Property TypeID="XOM.Exchange.Custom.MailboxClass"
PropertyID="LastLogonTime" />
</DiscoveryClass>
</DiscoveryTypes>
- <DataSource ID="DataSource"
RunAs="MicrosoftExchangeServer2007Library6064890!Microsoft.Exchange2007.Account.ViewOnly" TypeID="XOM.Exchange.Custom.MailboxDS">
<InternalSec>300</InternalSec>
<TimeoutSec>300</TimeoutSec>
<DBName>$Target/Property[Type="MicrosoftExchangeServer2007Library6064890!Microsoft.Exchange2007.Component.Database"]/Identity$</DBName>
</DataSource>
</Discovery>
Updated Data Source:
<Configuration p1:noNamespaceSchemaLocation="C:\Documents and
Settings\nwelch.NA\Local Settings\Temp\1\DS - PowerShell Script Discovery
Provider.xsd" xmlns:p1="http://www.w3.org/2001/XMLSchema-instance">
<IntervalSeconds>$Config/InternalSec$</IntervalSeconds>
<SyncTime>00:00</SyncTime>
<ScriptName>GetMailbox.ps1</ScriptName>
<ScriptBody>
param($Element,$Target,$Identity)
$scomapi = new-object -comObject 'MOM.ScriptAPI'
#Event Log (OpsMgr) Debug Statement
#$scomapi.logscriptevent("Mailbox Discovery Test",100,0,"Params: $Element,
$Target, $Identity")
#Create discovery "bag"
$DiscData = $scomapi.CreateDiscoveryData(0, $Element, $Target)
#Get list of mailboxes on the db with all properties
$list = Get-MailboxStatistics -database "$Identity"
$count=0
foreach ($i in $list)
{$Instance =
$DiscData.CreateClassInstance("$MPElement[Name='XOM.Exchange.Custom.MailboxClass']$")
$instance.AddProperty("$MPElement[Name='MicrosoftExchangeServer2007Library6064890!Microsoft.Exchange2007.Component.Database']/Identity$", $Identity)
$Instance.AddProperty("$MPElement[Name='XOM.Exchange.Custom.MailboxClass']/Name$", $i.DisplayName)
$Instance.AddProperty("$MPElement[Name='XOM.Exchange.Custom.MailboxClass']/LastLogonTime$", $i.LastLogonTime)
$Instance.AddProperty("$MPElement[Name='XOM.Exchange.Custom.MailboxClass']/StorageLimitStatus$", $i.StorageLimitStatus)
$Instance.AddProperty("$MPElement[Name='XOM.Exchange.Custom.MailboxClass']/TotalItemSize$", $i.TotalItemSize)
$Instance.AddProperty("$MPElement[Name='XOM.Exchange.Custom.MailboxClass']/ServerName$", $i.ServerName)
$Instance.AddProperty("$MPElement[Name='XOM.Exchange.Custom.MailboxClass']/StorageGroupName$", $i.StorageGroupName)
$Instance.AddProperty("$MPElement[Name='XOM.Exchange.Custom.MailboxClass']/DatabaseName$", $i.DatabaseName)
#$temp=$i.displayname
#$scomapi.logscriptevent("Mailbox Discovery Test",100,0,"$count $temp")
$DiscData.AddInstance($Instance)
$count=$count+1
}
#Event Log (OpsMgr) Debug Statement
$scomapi.logscriptevent("Mailbox Discovery Test",100,0,"$Identity; Total
Items = $count")
$scomapi.Return($DiscData)
#$DiscData
</ScriptBody>
<SnapIns>
<SnapIn>Microsoft.Exchange.Management.PowerShell.Admin</SnapIn>
</SnapIns>
<Parameters>
<Parameter>
<Name>Element</Name>
<Value>$MPElement$</Value>
</Parameter>
<Parameter>
<Name>Target</Name>
<Value>$Target/Id$</Value>
</Parameter>
<Parameter>
<Name>Identity</Name>
<Value>$Config/DBName$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSec$</TimeoutSeconds>
</Configuration>