***********************************************************************
' DisplayAllUsers.vbs *
' *
' Simple script that outputs all users in the domain and their ADsPath *
' *
' Paul Williams, msresource.net, July 2005. *
' Written: 05-07-2005 *
' *
' ***********************************************************************
Option explicit
dim oFso,oAttr
dim sDisplayName,sADsPath,sString
dim logf
' Define and create a log file
set oFso=createObject(Scripting.FileSystemObject)
set logf=oFso.createTextFile(LogFile.log,true)
queryDS
wscript.echo Script finished.
' *********************************************************************
' queryDS()
'
' Subcreates an ADO connection, searches the DS for all users,
' and then writes the info. to the log file.
'
' *********************************************************************
Private Sub queryDS()
dim oRootDse,oCommand,oConnection,oRs,oRecordSet
dim sBase,sFilter,sAttributes,sScope,sQuery
-> Create and define an ADO Connection object
set oCommand = createObject(ADODB.Command)
set oConnection = createObject(ADODB.Connection)
oConnection.Provider = ADsDSOObject
oConnection.Open Active Directory Provider
oCommand.ActiveConnection = oConnection
set oRootDse = getObject(LDAP://RootDSE)
sBase = <LDAP://&oRootDse.get(defaultNamingContext)&>;
sFilter = (&(objectclass=user)(objectcategory=person));
sAttributes = displayName,ADsPath;
sScope = subtree
sQuery = sBase & sFilter & sAttributes & sScope
oCommand.CommandText = sQuery
oCommand.Properties(Page Size) = 100
oCommand.Properties(Timeout) = 30
oCommand.Properties(Cache Results) = false
set oRecordSet=oCommand.Execute
do until oRecordSet.EOF
sDisplayName=oRecordSet.fields(displayName)
sADsPath=oRecordSet.fields(ADsPath)
write sDisplayName&vbTab&[ &sADsPath& ]
oRecordSet.moveNext
loop
oConnection.close
End Sub
' *********************************************************************
' write(string messageToEcho)
'
' Sub routine simply writes the passed string to file.
' Sub used for outputting all information to file.
'
'
' *********************************************************************
Private Sub write(sMessage)
logf.writeLine(sMessage)
End Sub
' *********************************************************************
' echo(string messageToEcho)
'
' Sub routine simply echos the passed string.
' Sub used for outputting all information to the screen/ console.
'
' Mainly used for debugging and testing, but left for completeness.
'
' *********************************************************************
Private Sub echo(sMessage)
wscript.echo sMessage
End Sub