|
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"
|