Re: Enumerating StorageGroups
- From: "Glen Scales [MVP]" <gscales@xxxxxxxxxxxxxxxxxxx>
- Date: Thu, 28 Apr 2005 15:27:22 +1000
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
.
- Follow-Ups:
- Re: Enumerating StorageGroups
- From: Erik
- Re: Enumerating StorageGroups
- References:
- Enumerating StorageGroups
- From: Erik
- Enumerating StorageGroups
- Prev by Date: Re: Upating Exchange Database from a ASPX form??
- Next by Date: Re: hidden a event in contacts
- Previous by thread: Enumerating StorageGroups
- Next by thread: Re: Enumerating StorageGroups
- Index(es):
Relevant Pages
|