Skip to content

Instantly share code, notes, and snippets.

@Chaz6
Created October 31, 2012 17:39
Show Gist options
  • Save Chaz6/3988566 to your computer and use it in GitHub Desktop.
Save Chaz6/3988566 to your computer and use it in GitHub Desktop.
List newly created objects in an Active Directory domain
On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
Dim strTimestamp
strTimestamp = "20120901000000.0Z"
set objRootDSE = GetObject("LDAP://RootDSE")
RootDN = objRootDSE.Get("defaultNamingContext"))
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
strQuery = "SELECT ADsPath FROM 'LDAP://RootDN & "' WHERE objectCategory='user' AND whenCreated>='" & strTimestamp & "'"
objCommand.CommandText = strQuery
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Wscript.Echo objRecordSet.Fields("ADsPath").Value
objRecordSet.MoveNext
Loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment