Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Exchange
2000.active.directory
2000.admin
2000.announcements
2000.app.conversion
2000.applications
2000.clients
2000.clustering
2000.connectivity
2000.development
2000.documentation
2000.general
2000.information.store
2000.interop
2000.kms
2000.misc
2000.protocols
2000.realtime.collabo.
2000.setup
2000.transport
2000.win2000
admin
application.conversion
applications
clients
clustering
connectivity
design
development
misc
mobility
setup
tools
  
 
date: Wed, 27 Apr 2005 05:28:04 -0700,    group: microsoft.public.exchange2000.development        back       


Enumerating StorageGroups   
Looking at building some automated mailbox management solutions and was 
trying to figure out to the best way (in VB.Net) to enumerate the available 
storage groups and determine the number of mailboxes currently allocated to 
each of them.

I've seen a number of code snippets that are partial solutions, but most of 
them are either bit of VB or WMI and we're trying to do everything in .net 
(but not c#)

Cheers,

Erik
date: Wed, 27 Apr 2005 05:28:04 -0700   author:   Erik

Re: Enumerating StorageGroups   
There are a few ways you could go with this you could use an Interop and use 
CDOEXM and then use the System.Management namespace to do some WMI. Or you 
can do it all with the System.Directoryservices namespace the thing to 
remember is that mailboxes are contained in mailstores and mailstores within 
Storage groups. So to get the total number of mailboxes in a storage group 
you need to add all the mailstore counts together something like this should 
work okay.

    Sub Main()
        Dim strservername As String = "servername"
        Dim RootDSE As New 
System.DirectoryServices.DirectoryEntry("LDAP://RootDSE")
        Dim RootPath As String = "LDAP://" + 
RootDSE.Properties("configurationNamingContext").Value
        Dim ConfigContainer As New 
System.DirectoryServices.DirectoryEntry(RootPath)
        Dim ConfigSearcher As New 
System.DirectoryServices.DirectorySearcher(ConfigContainer)
        ConfigSearcher.Filter = "(&(objectCategory=msExchExchangeServer)cn=" 
& strservername & ")"
        ConfigSearcher.SearchScope = 
System.DirectoryServices.SearchScope.Subtree
        Dim result As System.DirectoryServices.SearchResult = 
ConfigSearcher.FindOne()
        Dim colsgroups As DirectoryServices.SearchResultCollection
        Dim sresult As DirectoryServices.SearchResult
        Dim colmstores As DirectoryServices.SearchResultCollection
        Dim sresult1 As DirectoryServices.SearchResult
        Dim proparray() As String
        Dim stcount As Int32
        colsgroups = 
searchcontainer(result.Properties("distinguishedName")(0).ToString(), 
"(objectCategory=msExchStorageGroup)")
        For Each sresult In colsgroups
            Console.WriteLine(sresult.GetDirectoryEntry().Properties("cn").Value)
            colmstores = 
searchcontainer(sresult.Properties("distinguishedName")(0).ToString(), 
"(objectCategory=msExchPrivateMDB)")
            stcount = 0
            For Each sresult1 In colmstores
                Console.WriteLine(" " + 
sresult1.GetDirectoryEntry().Properties("cn").Value)
                Console.WriteLine("     Number of Mailboxes: " & 
sresult1.GetDirectoryEntry().Properties("homeMDBBL").Count)
                stcount = stcount + 
sresult1.GetDirectoryEntry().Properties("homeMDBBL").Count
            Next
            Console.WriteLine("Total Number of Mailboxes in Storage Group: " 
& stcount)
            Console.WriteLine("")
        Next

    End Sub

    Function searchcontainer(ByVal srvPath As String, ByVal strfilter As 
String)
        Dim ldapPath As String = "LDAP://" + srvPath
        Dim ServerContainer As New 
System.DirectoryServices.DirectoryEntry(ldapPath)
        Dim ServerSearcher As New 
System.DirectoryServices.DirectorySearcher(ServerContainer)
        ServerSearcher.Filter = strfilter
        ServerSearcher.SearchScope = 
System.DirectoryServices.SearchScope.Subtree
        ServerSearcher.PropertiesToLoad.Add("cn")
        ServerSearcher.PropertiesToLoad.Add("distinguishedName")
        ServerSearcher.PropertiesToLoad.Add("homeMDBBL")
        Dim colsrvresult As System.DirectoryServices.SearchResultCollection 
= ServerSearcher.FindAll()
        Return colsrvresult
    End Function

Cheers
Gen


"Erik"  wrote in message 
news:2AA04767-81A0-450C-B87C-05957C28481C@microsoft.com...
> Looking at building some automated mailbox management solutions and was
> trying to figure out to the best way (in VB.Net) to enumerate the 
> available
> storage groups and determine the number of mailboxes currently allocated 
> to
> each of them.
>
> I've seen a number of code snippets that are partial solutions, but most 
> of
> them are either bit of VB or WMI and we're trying to do everything in .net
> (but not c#)
>
> Cheers,
>
> Erik
date: Thu, 28 Apr 2005 15:27:22 +1000   author:   Glen Scales [MVP]

Re: Enumerating StorageGroups   
Looks like the sort of thing I was looking for - I'll go give that a spin and 
see where it gets me.  Much appreciated...

Erik

"Glen Scales [MVP]" wrote:

> There are a few ways you could go with this you could use an Interop and use 
> CDOEXM and then use the System.Management namespace to do some WMI. Or you 
> can do it all with the System.Directoryservices namespace the thing to 
> remember is that mailboxes are contained in mailstores and mailstores within 
> Storage groups. So to get the total number of mailboxes in a storage group 
> you need to add all the mailstore counts together something like this should 
> work okay.
> 
>     Sub Main()
>         Dim strservername As String = "servername"
>         Dim RootDSE As New 
> System.DirectoryServices.DirectoryEntry("LDAP://RootDSE")
>         Dim RootPath As String = "LDAP://" + 
> RootDSE.Properties("configurationNamingContext").Value
>         Dim ConfigContainer As New 
> System.DirectoryServices.DirectoryEntry(RootPath)
>         Dim ConfigSearcher As New 
> System.DirectoryServices.DirectorySearcher(ConfigContainer)
>         ConfigSearcher.Filter = "(&(objectCategory=msExchExchangeServer)cn=" 
> & strservername & ")"
>         ConfigSearcher.SearchScope = 
> System.DirectoryServices.SearchScope.Subtree
>         Dim result As System.DirectoryServices.SearchResult = 
> ConfigSearcher.FindOne()
>         Dim colsgroups As DirectoryServices.SearchResultCollection
>         Dim sresult As DirectoryServices.SearchResult
>         Dim colmstores As DirectoryServices.SearchResultCollection
>         Dim sresult1 As DirectoryServices.SearchResult
>         Dim proparray() As String
>         Dim stcount As Int32
>         colsgroups = 
> searchcontainer(result.Properties("distinguishedName")(0).ToString(), 
> "(objectCategory=msExchStorageGroup)")
>         For Each sresult In colsgroups
>             Console.WriteLine(sresult.GetDirectoryEntry().Properties("cn").Value)
>             colmstores = 
> searchcontainer(sresult.Properties("distinguishedName")(0).ToString(), 
> "(objectCategory=msExchPrivateMDB)")
>             stcount = 0
>             For Each sresult1 In colmstores
>                 Console.WriteLine(" " + 
> sresult1.GetDirectoryEntry().Properties("cn").Value)
>                 Console.WriteLine("     Number of Mailboxes: " & 
> sresult1.GetDirectoryEntry().Properties("homeMDBBL").Count)
>                 stcount = stcount + 
> sresult1.GetDirectoryEntry().Properties("homeMDBBL").Count
>             Next
>             Console.WriteLine("Total Number of Mailboxes in Storage Group: " 
> & stcount)
>             Console.WriteLine("")
>         Next
> 
>     End Sub
> 
>     Function searchcontainer(ByVal srvPath As String, ByVal strfilter As 
> String)
>         Dim ldapPath As String = "LDAP://" + srvPath
>         Dim ServerContainer As New 
> System.DirectoryServices.DirectoryEntry(ldapPath)
>         Dim ServerSearcher As New 
> System.DirectoryServices.DirectorySearcher(ServerContainer)
>         ServerSearcher.Filter = strfilter
>         ServerSearcher.SearchScope = 
> System.DirectoryServices.SearchScope.Subtree
>         ServerSearcher.PropertiesToLoad.Add("cn")
>         ServerSearcher.PropertiesToLoad.Add("distinguishedName")
>         ServerSearcher.PropertiesToLoad.Add("homeMDBBL")
>         Dim colsrvresult As System.DirectoryServices.SearchResultCollection 
> = ServerSearcher.FindAll()
>         Return colsrvresult
>     End Function
> 
> Cheers
> Gen
> 
> 
> "Erik"  wrote in message 
> news:2AA04767-81A0-450C-B87C-05957C28481C@microsoft.com...
> > Looking at building some automated mailbox management solutions and was
> > trying to figure out to the best way (in VB.Net) to enumerate the 
> > available
> > storage groups and determine the number of mailboxes currently allocated 
> > to
> > each of them.
> >
> > I've seen a number of code snippets that are partial solutions, but most 
> > of
> > them are either bit of VB or WMI and we're trying to do everything in .net
> > (but not c#)
> >
> > Cheers,
> >
> > Erik 
> 
> 
>
date: Fri, 29 Apr 2005 07:36:08 -0700   author:   Erik

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us