Link to home
Start Free TrialLog in
Avatar of rbrosius0331
rbrosius0331Flag for Singapore

asked on

How can I list user logon names from Active Directory?

How can I print out a list of user logon accounts from my active directory (Microsoft Server 2003 R2 SP2).  The export function that I find in AD only lists the display name.  I do not need passwords, just the logon name.
Avatar of Cedric Obinna A.
Cedric Obinna A.
Flag of Nigeria image

http://manageengine.adventnet.com/products/ad-manager/windows-active-directory-logon-reports.html
 I am afraid you have to buy that... you didn't indicate though whether you want to just view and print the user logons OR whether you want to incorporate it into an application you are developing... I assume the former. If it is not what you want, pls let us know.
run this in command prompt on your dc

dsquery user | dsget user -samid
Of course, you can redirect output to .txt file and print it:

dsquery user | dsget user -samid >> c:\userlist.txt
ASKER CERTIFIED SOLUTION
Avatar of Nivlesh
Nivlesh
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
try this
set objRootDSE = getobject("LDAP://RootDSE")
 
 
strExportFile = "C:\MyExport.xls" 
 
strRoot = objRootDSE.Get("DefaultNamingContext")
 
strfilter = "(&(objectCategory=Person)(objectClass=User)(department=brugere))"
strfilter = "(&(objectCategory=Person)(objectClass=User))"
 
 
 
strAttributes = "sAMAccountName,userPrincipalName,givenName,sn,"
 
strScope = "subtree"
 
set cn = createobject("ADODB.Connection")
set cmd = createobject("ADODB.Command")
 
cn.open "Provider=ADsDSOObject;"
cmd.ActiveConnection = cn
cmd.commandtext = "<LDAP://" & strRoot & ">;" & strFilter & ";" & _
		   strAttributes & ";" & strScope
 
set rs = cmd.execute
 
 
set objExcel = CreateObject("Excel.Application")
set objWB = objExcel.Workbooks.Add
set objSheet = objWB.Worksheets(1)
 
For i = 0 To rs.Fields.Count - 1
	objSheet.Cells(1, i + 1).Value = rs.Fields(i).Name
	objSheet.Cells(1, i + 1).Font.Bold = True
Next
 
 
objSheet.Range("A2").CopyFromRecordset(rs)
' Save the workbook
objWB.SaveAs(strExportFile)
 
 
rs.close
cn.close
set objSheet = Nothing
set objWB =  Nothing
objExcel.Quit()
set objExcel = Nothing

Open in new window

Avatar of rbrosius0331

ASKER

It's easy when your are accomplished in a subject.  Thanks for the answer.
you are welcome :)