Active Directory 脚本问题

Active Directory 脚本问题

我们的 Active Directory 中有 100 个用户。如何使用脚本仅导出昨天添加的用户?

答案1

以下dsquery将返回 2011-02-04 之后创建的用户对象:

dsquery * domainroot -filter "(&(objectCategory=person)(whenCreated>=20110204000000.0Z))" -limit 0

答案2

我有这个 vbscript,用于将 AD 用户及其属性导出到 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

相关内容