我有一个脚本,显示特定 AD 用户所属的组的过滤列表。它作为 VBS 文件工作得非常好,但是当导入到 HTA 或 HTML 文件时,在运行下面的“objRecordSet.MoveFirst”行时,它会给我一个“无法识别搜索过滤器”错误消息。
Dim User
Dim DIA
Dim GroupList
DIA = "No"
User = "UserNic"
Const ADS_SCOPE_SUBTREE = 2
Const E_ADS_PROPERTY_NOT_FOUND = &h8000500D
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
objCommand.CommandText = _
"SELECT memberOf FROM 'LDAP://dc=company,dc=com' WHERE objectCategory='user' And mailnickname='" & User & "'"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
arrMemberOf = objRecordSet.Fields("memberOf")
if isArray(objRecordSet.Fields("memberOf")) Then
For Each x in arrMemberOf
If InStr(x,"GroupFilter") <> 0 Then
Group = x
Group = Right(Group,Len(Group)-3)
Group = Left(Group,InStr(Group,",")-1)
GroupList = Group & vbCrLf & GroupList
End If
If InStr(x,"DIA") <> 0 Then DIA = "Yes"
Next
End if
objRecordSet.MoveNext
Loop
WScript.Echo GroupList
WScript.echo "DIA: " & DIA
我还有另一个几乎相同的脚本,它可以在 HTA/HTML 格式下工作。这个仅显示电子邮件帐户的转发位置(如果有的话):
Const ADS_SCOPE_SUBTREE = 2
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
objCommand.CommandText = _
"SELECT Name, altRecipient FROM 'LDAP://dc=company,dc=com' WHERE objectCategory='user' And Name='*" & Hosp & "' And altRecipient='*'"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Count = 0
Do Until objRecordSet.EOF
Name(Count) = objRecordSet.Fields("Name").Value
Forward(Count) = objRecordSet.Fields("altRecipient").Value
arrLines = Split(Forward(Count),",")
search = Filter(arrLines,"CN=",True,1)
for each x in search
Forward(Count) = x
Next
Forward(Count) = Replace(Forward(Count),"CN=","")
objRecordSet.MoveNext
Count = Count + 1
Loop
我似乎找不到每个脚本的“objRecordSet.MoveFirst”行之间的任何功能差异。
请帮忙!
编辑:
这里的结果相同。尝试了替代代码块来执行相同的操作 - 作为 VBS 但不是 HTA 可以正常工作:
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText = "<LDAP://dc=domain,dc=com>;" & "(&(objectCategory=Person)(mailnickname=" & User & "));" & "distinguishedName,Name;subtree"
Set objRecordSet = objCommand.Execute
intCount = 0
If objRecordSet.EOF Then
Set WshShell = CreateObject("WScript.Shell")
message = WshShell.Popup ("Unable to find a user with the alias '" & User & "'! Please try again...",, "programname", 0 + 16)
'Exit Sub
Else
While NOt objRecordSet.EOF
intCount = intCount + 1
objRecordSet.MoveNext
WEND
If intCount = 1 Then
objRecordSet.MoveFirst
Set objUser = GetObject("LDAP://" & objRecordSet.Fields("distinguishedname"))
Set colGroups = objUser.Groups
For Each objGroup in colGroups
Group = objGroup.CN
GroupList = Group & vbCrLf & GroupList
Next
End If
End If
WScript.Echo GroupList