Become a Columnist Microsoft Exchange Site Microsoft Support SiteMSDN Exchange Site

   

Subscribe to OutlookExchange
Anderson Patricio
Ann Mc Donough
Bob Spurzem
Brian Veal
Catherine Creary
Cherry Beado
Colin Janssen
Collins Timothy Mutesaria
Drew Nicholson
Fred Volking
Glen Scales
Goran Husman
Guy Thomas
Henrik Walther
Jason Sherry
Jayme Bowers
John Young
Joyce Tang
Justin Braun
Konstantin Zheludev
Kristina Waters
Kuang Zhang
Mahmoud Magdy
Martin Tuip
Michael Dong
Michele Deo
Mitch Tulloch
Nicolas Blank
Pavel Nagaev
Ragnar Harper
Ricardo Silva
Richard Wakeman
Russ Iuliano
Santhosh Hanumanthappa
Steve Bryant
Steve Craig
Todd Walker
Tracey J. Rosenblath
 
 
How Many Users in a particular OU have an Exchange Mailbox? Columnist's Index
Page 1

I was recently asked what sounded like a very simple question. “How many users do we have that are email enabled?”. Turns out the answer wasn’t as simple as I thought it would be, especially since I was trying to answer the question for a single department head, not for the entire domain. Since all departments in my domain are organized by OU, it seemed reasonable that all I needed to do was determine how many users in the OU were mailbox enabled. Not only could I not tell how many users in the OU had email accounts, I couldn’t even tell exactly how many users were in the OU.

The following script solved the problem for me. It creates a report on the root of the C: drive which contains the samAccountName (pre Windows 2000 logon name), first name and last name of all users in the OU. For any user that is not mailbox enabled, ‘No Mailbox’ will be tagged after their other information. The bottom of the report contains the number of mailbox enabled users and the number of non-mailbox enabled users. Be sure to modify the myOU statement to match your environment. 

Feel free to email me with comments or questions.  

'On Error Resume Next
'This script will create a text file on the root of C:
'containing the name of all users in the OU.
'If the user has no mailbox it will be noted, also counts
'the # of mail enabled users in the OU, and # of users
'with no email
'Kristina L Waters, 02/03/05

Set objFSO = CreateObject("Scripting.FileSystemObject")
'The file will be created on the root of the C: drive
Set objOutputFile = objFSO.CreateTextFile("c:\Mail_Enabled_Users.txt", True)

'Edit the following line to reflect your environment
myOU = "OU=SomeOU,OU=Users,dc=domain,dc=com"

i = 0
x = 0

Set objOU = GetObject("LDAP://"& myOU)

For Each objCont in objOU
'Check to see if the object is a User account

if objCont.Class = "user" then
set objUser = Getobject("LDAP://"& objCont.distinguishedname)
If objUser.homemdb <> "" then
strOutput = objUser.samaccountname &";"& objUser.sn & _
";"& objUser.GivenName &";"
objOutputFile.WriteLine strOutput
i = i + 1
else
strOutput = objUser.samaccountname &";"& objUser.sn & _
";"& objUser.GivenName &";No Mailbox;"
objOutputFile.WriteLine strOutput
x = x + 1
end if
End If

Next

objOutputFile.WriteLine "Total number of email enabled users is "& i &"."
objOutputFile.WriteLine "Total number of users with no email is "& x &"."

'Clean up
objOutputFile.Close
set objRootDSE = Nothing
set objDomain = Nothing
set objFSO = Nothing
set objOutputFile = Nothing
set objOU = Nothing
set objUser = Nothing

wscript.Echo "All Done"


How Many Users in a particular OU have an Exchange Mailbox? Columnist's Index
Page1

Disclaimer: Your use of the information contained in these pages is at your sole risk. All information on these pages is provided "as is", without any warranty, whether express or implied, of its accuracy, completeness, fitness for a particular purpose, title or non-infringement, and none of the third-party products or information mentioned in the work are authored, recommended, supported or guaranteed by Stephen Bryant or Pro Exchange. OutlookExchange.Com, Stephen Bryant and Pro Exchange shall not be liable for any damages you may sustain by using this information, whether direct, indirect, special, incidental or consequential, even if it has been advised of the possibility of such damages.

Copyright Stephen Bryant 2008