【发布时间】:2015-08-21 19:12:15
【问题描述】:
我的老板要求更新我在此之前使用的一个非常旧的脚本,以将 AD 中的 State 字段添加到其中。以下是返回所有活动用户及其电子邮件地址的脚本。现在我只需要添加State:
Const ADS_PROPERTY_NOT_FOUND = &h8000500D
Const ADS_UF_ACCOUNTDISABLE = 2
Const strX400Search = "X400"
Set objRootDSE = GetObject("LDAP://rootDSE")
strDomain = objRootDSE.Get("defaultNamingContext")
strADPath = "LDAP://" & strDomain
Set objDomain = GetObject(strADPath)
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 5000
objCommand.CommandText = "<" & strADPath & ">" & _
";(&(|(objectClass=contact)(objectClass=group)) (mail=*))" & _
";distinguishedName,displayName,mail,proxyAddresses;subtree"
Set objRecordSet = objCommand.Execute
AddressCount = 0
varDisabledCounter = 0
objCommand.CommandText = "<" & strADPath & ">" & _
";(&(objectClass=user)(mail=*))" & _
";distinguishedName,displayName,mail,proxyAddresses;subtree"
Set objRecordSet = objCommand.Execute
strResult = strResult & "Name" & "," & "Email" & VbCrLf
While Not objRecordSet.EOF
strUserDN = objRecordSet.Fields("distinguishedName")
strUserDN=Replace(strUserDN,"/","\/")
set objUser= GetObject("LDAP://"& strUserDN & "")
If objUser.AccountDisabled = FALSE Then
strResult = strResult & objUser.givenName & " " & objUser.sn & ","
strResult = strResult & objUser.mail
strResult = strResult & VbCrLf
End If
objRecordSet.MoveNext
Wend
Set objFileSystem = CreateObject("Scripting.FileSystemObject")
Set objOutputFile = objFileSystem.CreateTextFile("C:\Email List.csv")
objOutputFile.Write strResult
LF=chr(10)
WScript.Echo "Done - Please Check C:\Email List.csv to see your file." & _
LF & LF & "If you have any questions please contact Kevin Reed"
【问题讨论】:
-
那么,您遇到了什么问题?
-
可行,但也尝试将其状态添加为列。
-
所以添加相应的属性(
st)。再说一遍,你遇到了什么问题?
标签: vbscript active-directory ldap