Powershell – How to get AD users from a list of Exchange 2003 mailboxes

active-directoryexchange-2003powershell

I have a great VBscript which will list all my Exchange 2003 mailboxes with a size under a given size.

I have another great VBscript which accepts a list of users and sets the quotas for each of those users.

Can anyone fill in the gap, and point me in the direction of a method (VBscript or otherwise) by which I can set the quota for all users who have a mailbox under a certain limit?

I'm trying to reduce my mailbox limits, and want to start by enforcing that limit for users who are already below it. That way the bigger problem of getting people below the new limit doesn't get any bigger!

Update: Thanks to Evan Anderson I found that I need to convert my GUID to another format for use in an LDAP lookup. Microsoft have a knowledge base article that explains how to do this, but I don't have GUIDs in the required format. There is another kb article that describes "how to convert a string formatted GUID to a hexadecimal string form for use when querying the active directory", but the script throws an error.

Update 2: Ok – forget the VB script. I found a more succinct way to get my data using PowerShell.

$computers = "vexch01","vexch02"
foreach ($computer in $computers) {
  Get-Wmiobject -namespace root\MicrosoftExchangeV2 -class Exchange_Mailbox -computer $computer | sort-object -desc Size | select-object MailboxDisplayName,StoreName,@{Name="Size/Mb";Expression={[math]::round(($_.Size / 1024),2)}}, MailboxGUID | Export-Csv -notype -Path $computer.csv 
}

Currently this outputs the MailboxGUID as a string type GUID (e.g. {21EC2020-3AEA-1069-A2DD-08002B30309D}). I want to look up users in AD by this, but AD stores them in octetBytes format.

I have found some powershell functions which will do the conversion but only when the curly braces are removed. The Guid.ToString method should supply this, but I can't get it to work in the above.

However, if I could figure out how to do that, the Guid.ToByteArray method might get me even closer.

Has anyone cracked this?

Best Answer

Without seeing your scripts it's difficult to give you a "turn key" solution. You'll probably be able to match up user accounts to mailboxes by doing an LDAP search against the msExchMailboxGuid attribute, depending on whether or not your mailbox size script can return that. That GUID will disambiguously pair a mailbox and AD user account across your entire Exchange organization.