Posted by: Colin Smith
Exchange Scripting, Powershell, Scripting
Now that I have both the users stored in an array and the mailboxes stored in another array it is time to start making sure that I am working with a mailbox and a user account that match up. I do not want to look at my user account and Johns Mailbox and start making changes based on what I find in those two accounts that do not affect the same account. So here is what I did. It is really very simple and I will be adding more to this later for filtering of accounts and decision making. For now though here is the basics of how to make sure that the accounts are matching.
foreach($mailbox in $mailboxes)
$exsam = $mailbox.SamAccountName
foreach ($user in $users)
$adsam = $user.SamAccountName
if ($exsam -eq $adsam)
Echo “We have a match”
So I first get the samaccountname from Exchange and then I do the same for AD. Once I find that the Sam Names are the same I know that I have a match. That simple.