Showing posts with label Active Directory. Show all posts
Showing posts with label Active Directory. Show all posts

Tuesday, January 18, 2011

PowerShell with Exchange 2003

We recently had a requirement to discover the details of exceptional mailboxes in Exchange 2003. We were aware of the Management Tools and in particular the Management Shell for Exchange 2007 which allows you to query mailbox information with a range of PowerShell commands, however we were not aware that you could use the 2007 tools to query 2003 data. In hindsight it makes sense as the data we were looking to query is held in Active Directory!

The particular scenario we were looking to find was where the UseDatabaseRetentionDefaults property is set to False. We had discovered 1 mailbox which met this criteria and the RetainDeletedItemsFor property was also set to 0, therefore once a mail item was deleted it was gone. The following command quickly output all of the mailboxes in this scenario:

[PS] C:\WINDOWS\system32>Get-Mailbox | Where {$_.UseDatabaseRetentionDefaults -eq $False} | select Name,UseDatabaseRetentionDefaults,RetainDeletedItemsFor | Export-Csv C:\UseDatabaseRetentionDefaults.csv

This web page has some other useful queries for finding other exceptional mailboxes in Exchange with both LDAP queries and the Management Tools: Find Exceptional Mailboxes in Exchange Environment.

Monday, May 17, 2010

Active Directory - Enumerating Members of a Group

Was looking today how to enumerate the members of an AD Group - found an easy example here: http://msdn.microsoft.com/en-us/library/ms180906(VS.80).aspx
DirectoryEntry group = new DirectoryEntry("LDAP://CN=Sales,DC=Fabrikam,DC=COM");
object members = group.Invoke("Members", null);
foreach(object member in (IEnumerable)members)
{
DirectoryEntry x = new DirectoryEntry(member);
Console.WriteLine(x.Name);
}