List of Users

Here’s a simple script to return all users within  your domain.

strNamingContext = "defaultNamingContext"
strConnectionString = "Provider=ADsDSOObject"
strFilter= "ObjectCategory='user'"
'[Functions] ****************************************
Function removeCN(inputString)
  Dim textValue 
     textValue = inputString
 Dim textLength
     textLength = Len(textValue)
     textValue = Right(textValue, textLength-3)
     removeCN = textValue   
End Function
'****************************************************
Set objAdRootDSE = GetObject("LDAP://RootDSE")
Set objRS = CreateObject("ADODB.RecordSet")
 objNamingContext = objAdRootDSE.Get(strNamingContext)
 strSQLQuery = "SELECT * FROM 'LDAP://" & objNamingContext &_
               "' WHERE " & strFilter & "ORDER BY NAME"
objRS.Open strSQLQuery, strConnectionString
On Error Resume Next
Do until objRS.eof
 Set objServer = GetObject(objRS.Fields.Item(0))
 strComputer = removeCN(objServer.Name)
 WScript.Echo strComputer
 objRS.MoveNext
Loop

Powered by WordPress with [GimpStyle]
Entries and comments feeds.