How to use Exchange Management Shell to find users based on attributes

Hello folks,

There are a bunch of questions in Microsoft Forums asking how to retrieve information from Exchange Server 2007, such as: how to search all users from a specific department or how many users that have redirection and so forth. Also, some beginners may find complicated to get this information using Exchange Management Shell. So.. I’m going to use a simple scenario and all methods used here can be used to retrieve any other information just comparing values. Let’s get some action…

Scenario: Your boss is going to change the company SMTP address and he wants to know how many users will not receive the new SMTP Address coming from E-mail Address Policies because they have the Automatic E-mail Address Policie option disabled. Let’s say also that you have no idea what is the attribute name of that specificoption, so.. how can you do that?

First of all, find a guinea pig that can be your mailbox or any other user, we are not going to do nothing special just change some attributes in order to find the attribute name that will be used later on in the final query.

First step, open Exchange Management Console, expand Recipient Configuration and double click in your test user, click on E-mail Addresses tab and make sure that the option that you want to create a report is selected. Then, open an Exchange Management Shell session and type in the following cmdlet:

Get-Mailbox <UserName> | FL

Secont step, let’s go back to Exchange Management Console and double click on the same test account and now uncheck the option Automatically update e-mail address based on e-mail address policy and click on Apply and OK. Open a new Exchange Management Shell (We are not going to use the current Exchange Management Shell session must be new one to facilitate the next step) and run the same cmdlet that we had run in the last step, as follows:

Get-Mailbox <UserName> | FL

Why? Because you are going to comparte the differences between the first run and the second run of “Get-Mailbox <UserName> | FL” cmdlet and the difference will be what you are looking for, in our example we want to know the attribute how controls who has the E-mail Address Policy with a disable value, as shown in below.

Okay, now that you know the attribute you just to use it in a pipe to get information from your entire organization, as follows:

Get-Mailbox | where { $_.<AttributeName> -eq <value> }

In our example will be:
Get-Mailbox | where { $_.EmailAddressPolicyEnabled -eq 0 }

Okay, Do you want to impress your boss with a .csv report? 🙂 Not a problem, just add ” | export-csv c:\<file-name>.csv” at the end and that’s all!

Anderson Patricio

Leave a Reply

Your email address will not be published. Required fields are marked *