By David Wiseman (Administrator)Created 14 Jan 2006, Modified 23 Feb 2008
My Rating:
Vote
Rating:
(1 votes)
Views:8532
Downloads:461

List users with mailbox

Language:  VBScript

Compatibility

Windows XP Yes Windows 2003 Yes
Windows 2000 Unknown Windows NT Unknown
Vista Unknown Windows 2008 Unknown
Description

Creates a CSV file of all the users in the domain that have an Exchange mailbox

Code

Line Numbers: On  Off      Plain Text
const FileName = "userswithmailboxes.csv"

set cn = createobject("ADODB.Connection")
set cmd = createobject("ADODB.Command")
set rs = createobject("ADODB.Recordset")

cn.open "Provider=ADsDSOObject;"
cmd.activeconnection = cn

set objRoot = getobject("LDAP://RootDSE")

cmd.commandtext = "<LDAP://" & objRoot.get("defaultNamingContext") & _
		">;(&(objectClass=User)(HomeMDB=*));samaccountname,sn,givenname;subtree"
'**** Bypass the 1000 record limitation ****
cmd.properties("page size") = 1

set rs=cmd.execute

set objFSO = createobject("Scripting.FileSystemObject")
set objCSV = objFSO.createtextfile(FileName)
q = """"


while rs.eof <> true and rs.bof <> true
	objcsv.writeline(q & rs("samaccountname") &  q & "," & q  & _
			rs("sn") & q & "," & q & rs("givenName") & q)
	rs.movenext
wend

objCSV.Close
cn.close
	
wscript.echo "Finished"

 


Got a useful script? Click here to upload!


 

  Post Comment
Order By:  
User Comments
      
Be the first to post a comment!