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" <eableson@xxxxxxxxxx> wrote in message
news:2AA04767-81A0-450C-B87C-05957C28481C@xxxxxxxxxxxxxxxx
> 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


.



Relevant Pages

  • Re: Enumerating StorageGroups
    ... Erik ... > remember is that mailboxes are contained in mailstores and mailstores within ... So to get the total number of mailboxes in a storage group ... >> storage groups and determine the number of mailboxes currently allocated ...
    (microsoft.public.exchange2000.development)
  • Re: subfolders if INBOX are created in root dir.
    ... At the time that IMAP was designed, it was important to export whatever existing namespace for email that was out there. ... IMAP got caught in the middle in both wars, even though it didn't want to be in either one. ... I like Gmail's idea of using one mailbox with smart view that use flag names applied to messages, and otherwise abolishing separate mailboxes. ...
    (comp.mail.imap)
  • Re: Disaster Receovery Questions
    ... end up reinstalling the whole OS, and only had time to "copy" the storage groups to another location, they where clean shutdown before the copy, but it was a manual copy, not ntbackup. ... reinstall new Exchange 2003, giving it the same organization name as be4. ... at this point my idea is to end with a fresh exchange and fresh mailboxes, this will allow me to let users start recieving new emails and start working. ... to recover the old mails, my idea is to create a recovery storage group, dismount it, copy the "backup" database over the newly empty created recovery group and mount it again, and then use exMerge to merge the mailboxes from recovery group to the stable database. ...
    (microsoft.public.exchange.admin)
  • Re: Exchange Defrag v Moving mailboxes
    ... Our mailstores and therefore our .edb files are huge. ... there are some mailboxes that exceed the recommended 2GB ... for example we have 1 mailbox that exceeds 20GB and several that exceed ... exceed the 2GB limit, to defrag the mailstores? ...
    (microsoft.public.exchange.admin)
  • Re: Unable to create new mailboxes
    ... I deleted the "ghost" mailbox from each of the storage groups. ... went to a nice 2hour meeting about upgrading the ... Came back and it would now create the mailboxes and mount ... database but then wait 15 minutes before trying to mount it. ...
    (microsoft.public.exchange.admin)

Quantcast