Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problems with "PowerShell Script Discovery Provider"

332 views
Skip to first unread message

Nicole Welch

unread,
Feb 23, 2010, 9:38:05 AM2/23/10
to
I'm sure I'm missing something obvious, but my discovery returns nothing.
And unfortunately all my attempts to add debug statement (mainly to view vars
passed into the data source) have come to naught. So two questions: 1) What
am I doing wrong? 2) How do I print/log a debug statement about a variable
during execution? If I had more info to debug....

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>

Nicole Welch

unread,
Feb 25, 2010, 3:01:01 PM2/25/10
to
Found and corrected errors in my data source. FYI, this doc is very helpful!

http://download.microsoft.com/download/B/F/D/BFDD0F66-1637-4EA3-8E6E-8D03001E5E66/OM2007R2_MPModuleReference.docx

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>

0 new messages