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.
Microsoft Legacy OSActive Directory

Avatar of undefined
Last Comment
Nivlesh
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.
Avatar of cheeselover73
cheeselover73
Flag of Serbia image

run this in command prompt on your dc

dsquery user | dsget user -samid
Avatar of cheeselover73
cheeselover73
Flag of Serbia image

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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of ms-pro
ms-pro
Flag of Denmark image

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
rbrosius0331
Flag of Singapore image

ASKER

It's easy when your are accomplished in a subject.  Thanks for the answer.
Avatar of Nivlesh
Nivlesh
Flag of New Zealand image

you are welcome :)
Active Directory
Active Directory

Active Directory (AD) is a Microsoft brand for identity-related capabilities. In the on-premises world, Windows Server AD provides a set of identity capabilities and services, and is hugely popular (88% of Fortune 1000 and 95% of enterprises use AD). This topic includes all things Active Directory including DNS, Group Policy, DFS, troubleshooting, ADFS, and all other topics under the Microsoft AD and identity umbrella.

86K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo