Last time we went through and got a list of all the mailboxes and out put all smtp addreses to $comparefile. This time we need to get all of the ad records that are associated with the same OU. Now to do this you need the quest ad tools. At least that is how I did it. So here we go, this is pretty easy.
$users = get-qaduser -service ms.contoso.microsoft.com -resultsize 0
So that line is not to tough and here is what it does. The -service switch will tell it what OU I want it to look in and this will include all child containers from that level. -ResultSize 0 just tells it to get them all without limiting how many results I get. So this gives me a list of all the user accounts that I am going to be dealing with and these user accounts should correspond with the mailbox info that I have already gathered.