Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

We have Active Directory with 100 users. How can I use a script to export only the users who were added yesterday?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

The following dsquery will return user objects created after 2011-02-04:

dsquery * domainroot -filter "(&(objectCategory=person)(whenCreated>=20110204000000.0Z))" -limit 0
share|improve this answer
    
thanks for your answer. –  Cell-o Feb 4 '11 at 11:40

I have this vbscript i'm using to export AD users and their properties to a csv :

Const ForAppending = 8
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_1779 = 1
Const ADS_NAME_TYPE_SID_OR_SID_HISTORY_NAME = 12

Set objOU = GetObject("LDAP://OU=users,DC=example,DC=com")

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("D:\temp\AD_Users_Export.csv")

Call enummembers(objOU)


Sub enumMembers(objOU)
On Error Resume Next

For Each objMember In objOU  

If ObjMember.Class = "user" Then


If Not (isempty(ObjMember.CN)) Then
        Initials = ObjMember.CN
Else
        Initials = ""
End If

If Not (isempty(objMember.GivenName)) Then
        FirstName = objMember.GivenName
Else
        FirstName = ""
End If

If Not (isempty(objMember.sn)) Then
        Lastname = ObjMember.sn
Else
        LastName = ""
End If

If Not (isempty(objMember.mail)) Then
        Mail = ObjMember.mail
Else
        Mail = ""
End If

If Not (isempty(objMember.whenCreated)) Then
        whencreated = ObjMember.whenCreated
Else
        whencreated = ""
End If



set objFolder = nothing
set objFile = nothing

Set objTextFile = objFSO.OpenTextFile ("D:\temp\AD_Users_Export.csv", ForAppending, True)


strText1 = FirstName & "," & Lastname & "," & Initials & "," & Mail & "," & strSidDec & "," & whencreated

objTextFile.WriteLine(strText1) 
objTextFile.Close

End If

If objMember.Class = "organizationalUnit" or OBjMember.Class = "container" Then 
enumMembers (objMember) 
End If

Next

End Sub
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.