我们正在从多个域迁移到单个域。作为该过程的一部分,用户帐户正在各种AD中移动。这导致一些脚本崩溃,因为他们试图从AD中的特定位置获取User对象。
如何修改以下内容以使其不是AD位置?
Set objBlahUser = GetObject("LDAP://CN=" & objNetwork.UserName & ",OU=ADMigration,OU=Blah Users,DC=blah,DC=loc")
提前致谢
答案 0 :(得分:3)
最简单的方法是使用Windows内置的NameTranslate对象
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
strNTName = "MyDomain\TestUser"
Set objTrans = CreateObject("NameTranslate")
objTrans.Init ADS_NAME_INITTYPE_GC, ""
objTrans.Set ADS_NAME_TYPE_NT4, strNTName
strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
这里有一篇很好的关于这个对象的文章:
答案 1 :(得分:0)
您是否只想指定主机名?假设AD结构的其余部分相同,那么您只需在绑定字符串中指定服务器名称:
Set objBlahUser = GetObject("LDAP://yourserver.com/CN=" & objNetwork.UserName & ",OU=ADMigration,OU=Blah Users,DC=blah,DC=loc")
答案 2 :(得分:0)
因此,无法从目录中进行内在搜索和选择对象。我不得不使用一个单独的函数来搜索并返回对象的DN以供以后使用。
userDN = GetUserDN(objNetwork.UserName,"server001","blah.loc")
If Not userDN = "Error" Then
Set objBlahUser = GetObject("LDAP://" & userDN)
End if
Function GetUserDN(strUserName, strServer, strDomain)
On Error Resume Next
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Properties("User ID") = strDomain & "\ReadADAccount"
objConnection.Properties("Password") = "ReadADAccountPwd"
objConnection.Open "Active Directory Provider"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText = _
"<LDAP://" & strServer & ">;(&(objectCategory=User)" & _
"(samAccountName=" & strUserName & "));distinguishedname;subtree"
Set objRecordSet = objCommand.Execute
If objRecordset.RecordCount = 0 Then
GetUserDN = "Error"
Else
GetUserDN = objRecordSet(0).value
End If
objConnection.Close
End Function