Sign in to follow this  
Followers 0
nobby

List users from Active Directory

7 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

you can also do a dsquery command with the -o samid option.

dsquery -o samid

Same basic ends, different means.

KilRoy

Share this post


Link to post
Share on other sites

Thank you very much for your help.


CheersNobby

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0