nobby Posted June 19, 2006 Share Posted June 19, 2006 Hi, Pardon my ignorance: I am trying to get a list of all users in a Domain (ADS). I only require the LoginName to be returned, no other information. I have tried to make sense of some scripts I found on the forum, but I am having some difficulties in isolating the parts I need. Any help would be most appreciated. CheersNobby Link to comment Share on other sites More sharing options...
Developers Jos Posted June 19, 2006 Developers Share Posted June 19, 2006 (edited) Untested but should be close: Local $objCommand = ObjCreate("ADODB.Command") Local $objConnection = ObjCreate("ADODB.Connection") $objConnection.Provider = "ADsDSOObject" $objConnection.Open ("Active Directory Provider") $objCommand.ActiveConnection = $objConnection Local $strBase = "<GC://dc=MyDom,dc=Inc>" Local $strFilter = "(&(objectCategory=person)(objectClass=user)(sAMAccountName=*))" Local $strAttributes = "cn,sAMAccountName,displayName,sn,distinguishedName" Local $strQuery = $strBase & ";" & $strFilter & ";" & $strAttributes & ";subtree" $objCommand.CommandText = $strQuery $objCommand.Properties ("Page Size") = 100 $objCommand.Properties ("Timeout") = 30 $objCommand.Properties ("Cache Results") = False $ADS_SCOPE_SUBTREE = 2 $objCommand.Properties ("searchscope") = $ADS_SCOPE_SUBTREE Local $objRecordSet = $objCommand.Execute While Not $objRecordSet.EOF ;~ $strName = $objRecordSet.Fields ("sAMAccountName").Value ;~ $strCN = $objRecordSet.Fields ("cn").value ;~ $strdisplayName = $objRecordSet.Fields ("displayName").value ;~ $strSN = $objRecordSet.Fields ("SN").value ;~ $strdistinguishedName = $objRecordSet.Fields ("distinguishedName").value FileWriteLine("Users.txt",$objRecordSet.Fields ("sAMAccountName").Value) $objRecordSet.MoveNext WEnd $objConnection.Close $objConnection = "" $objCommand = "" $objRecordSet = "" Edited June 19, 2006 by JdeB SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
jftuga Posted June 19, 2006 Share Posted June 19, 2006 I tested the script and it works great! Nice work. -John Admin_Popup, show computer info or launch shellRemote Manager, facilitates connecting to RDP / VNCProc_Watch, reprioritize cpu intensive processesUDF: _ini_to_dict, transforms ini file entries into variablesUDF: monitor_resolutions, returns resolutions of multiple monitorsReport Computer Problem, for your IT help deskProfile Fixer, fixes a 'missing' AD user profile Link to comment Share on other sites More sharing options...
KilRoy Posted June 19, 2006 Share Posted June 19, 2006 you can also do a dsquery command with the -o samid option. dsquery -o samid Same basic ends, different means. KilRoy Link to comment Share on other sites More sharing options...
nobby Posted June 20, 2006 Author Share Posted June 20, 2006 Thank you very much for your help. CheersNobby Link to comment Share on other sites More sharing options...
arcker Posted June 20, 2006 Share Posted June 20, 2006 jdeb method is the fastest way i've used it so much in my script it's an ADO search, the same as the search engine of the tool provided by AD now, you can do a lot more with ado, or dsquery (but i prefer ADO) list groups, users, OrganisationalUnit....users of a group -- Arck System _ Soon -- Ideas make everything "La critique est facile, l'art est difficile" Projects :[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list] Link to comment Share on other sites More sharing options...
ptrex Posted June 20, 2006 Share Posted June 20, 2006 @nobbyAn other way of retrieving the data is using the MS LOGPARSER.See second post : Look for Active DirectoryEnjoy !! Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now