Script: Server 2003 匯出群組成員的user account 資訊至文字檔
指定群組後, 直接查詢群組成員, 並匯出指定的欄位資訊
On ERROR RESUME NEXT
Const ADS_Property_Update = 2
Const ADS_SCOPE_SUBTREE = 2
Const ForAppending = 2
y=Year(Now)
m=Month(Now)
d=Day(Now)
s=Second(Now)
If (m<10) Then
m="0" & m
End If
If (d<10) Then
d="0" & d
End If
sDate = Y & M & D
'=================================
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("c:\Batch\"&sDate&"-Export_GAL.txt", ForAppending, True)
objTextFile.WriteLine "This Log Created at: " & Now()& vbCrLf
objTextFile.WriteLine
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
'=================================
Set objGroup = GetObject _
("LDAP://cn=""Head of Center, Office"",ou=Special_Account,ou=User,dc=aaa,dc=corp,dc=com")
objGroup.GetInfo
arrMemberOf = objGroup.GetEx("member")
WScript.Echo "Members:"
For Each strMember in arrMemberOf
WScript.echo "Group Members: "&strMember&""
Set sMemberName = ""&strMember&""
WScript.echo "sMemberName - "&sMemberName&""
'Wscript.Echo ""&sOffice1&""
'=================================
objCommand.Properties("Page Size") = 100000
objCommand.CommandText = _
"<LDAP://"&strMember&">;(&(objectCategory=user));AdsPath,cn,physicalDeliveryOfficeName,distinguishedName,displayName,department,company,targetAddress,mailNickname,telephoneNumber,sn;subtree"
Set objRecordSet = objCommand.Execute
'=================================
intCounter = 0
intAllCounter = 0
intNumber = 0
objRecordset.MoveFirst
'=================================
Do Until objRecordSet.EOF
intNumber = intNumber + 1
sAds = objRecordSet.Fields("AdsPath")
Wscript.echo ""&AdsPath&""
sCn = objRecordSet.Fields("cn")
Wscript.echo ""&sCn&""
sC = objRecordSet.Fields("c")
Wscript.echo ""&sC&""
sL = objRecordSet.Fields("l")
Wscript.echo ""&sL&""
sTitle = objRecordSet.Fields("title")
Wscript.echo ""&sTitle&""
sOffice = objRecordSet.Fields("physicalDeliveryOfficeName")
Wscript.echo ""&sOffice&""
sDn = objRecordSet.Fields("distinguishedName")
Wscript.echo ""&sDn&""
sIt = objRecordSet.Fields("instanceType")
Wscript.echo ""&sIt&""
sDisp = objRecordSet.Fields("displayName")
Wscript.echo ""&sDisp&""
sCom = objRecordSet.Fields("company")
Wscript.echo ""&sCom&""
sEmp = objRecordSet.Fields("employeeNumber")
Wscript.echo ""&sEmp&""
sExdn = objRecordSet.Fields("legacyExchangeDN")
Wscript.echo ""&sExdn&""
sDept = objRecordSet.Fields("department")
Wscript.echo ""&sDept&""
sTa = objRecordSet.Fields("targetAddress")
Wscript.echo ""&sTa&""
sMn = objRecordSet.Fields("mailNickname")
Wscript.echo ""&sMn&""
sAMA = objRecordSet.Fields("sAMAccountName")
Wscript.echo ""&sAMA&""
sTelNo = objRecordSet.Fields("telephoneNumber")
Wscript.echo ""&sTelNo&""
sSN = objRecordSet.Fields("sn")
Wscript.echo ""&sSN&""
sDisg = objRecordSet.Fields("distinguishedName")
sDisg = Trim(sDisg)
Set MyUser0 = GetObject ("LDAP://"&sDisg&"")
Secondary0 = ""
For each email in MyUser0.proxyAddresses
If Left (email,5) = "SMTP:" Then
PriEmail0 = Mid(email,6)
'WScript.Echo "Primary e-mail address: " & Mid (email,6)
Wscript.Echo "Primary Email:"&PriEmail0&" "
ElseIf Left (email,5) = "smtp:" Then
Secondary0 = Secondary0 & "," & Mid (email,6)
End If
Next
objTextFile.WriteLine(""&intNumber&";"&sCn&";"&sC&";"&sL&";"&sTitle&";"&sOffice&";"&sDn&";"&sIt&";"&sDisp&";"&sCom&";"&sCom&";"&sEmp&";"&sExdn&";"&sDept&";"&sTa&";"&sMn&";"&sAMA&";"&PriEmail0&";"&sTelNo&";"&sSn&"")
objRecordset.MoveNext
Wscript.Echo vbCrLf
Loop
Next
objTextFile.WriteLine
objTextFile.WriteLine("========================================")
objTextFile.WriteLine("A total of "&intNumber&" email accounts have been exported")
objConnection.Close
objTextFile.Close
Set objUser = Nothing
Set objRecordSet = Nothing
Set objConnection = Nothing
Set objCommand = Nothing
Set objgroup = Nothing
Blog Extended Reading
More Information & Reference
Comments
Post a Comment