1: '*******************************************************************************
2: 'migrateUsers.VBS: Copy proxyAddresses from a Domino contact to an AD user
3: '
4: 'Version: 0.1
5: 'Date: 2008/01/07
6: 'Author: RUI SILVA rui.silva(a)live.com
7: '
8: '*******************************************************************************
9:
10: Const ForReading = 1
11: Const ForWriting = 2
12: Const ADS_SCOPE_SUBTREE = 2
13: Const ADS_PROPERTY_UPDATE = 2
14:
15: Set objConnection = CreateObject("ADODB.Connection") 16: Set objCommand = CreateObject("ADODB.Command") 17: objConnection.Provider = "ADsDSOObject"
18: objConnection.Open "Active Directory Provider"
19: Set objCommand.ActiveConnection = objConnection
20:
21: objCommand.Properties("Page Size") = 1000 22: objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 23:
24: strName=InputBox("Enter username:") 25: objCommand.CommandText = _
26: "SELECT distinguishedName FROM 'LDAP://ou=Domino Contacts,dc=DOMAIN,dc=COM' WHERE objectCategory='user' " & _
27: "AND mailNickname='" & strName & "'"
28: Set objRecordSet = objCommand.Execute
29:
30: If objRecordset.RecordCount = 1 Then
31: strDN = objRecordSet.Fields("distinguishedName").Value 32: MsgBox(strDN & ": FOUND")
33: strDN = Replace(strDN, "/", "\/")
34: Set objContact = GetObject("LDAP://" & strDN) 35: arrProxyAddresses = objContact.GetEx("proxyAddresses") 36: nArr = UBound(arrProxyAddresses)
37: For n=0 To nArr
38: If InStr(arrProxyAddresses(n), "SMTP:") Then
39: strEmailAddr = Mid(arrProxyAddresses(n), 6)
40: End If
41: Next
42:
43: objCommand.CommandText = _
44: "SELECT distinguishedName FROM 'LDAP://ou=USERS,dc=DOMAIN,dc=COM' WHERE objectCategory='user' " & _
45: "AND sAMAccountName='" & strName & "'"
46: Set objRecordSet2 = objCommand.Execute
47:
48: If objRecordset2.RecordCount = 1 Then
49: strDN2 = objRecordSet2.Fields("distinguishedName").Value 50: MsgBox(strDN2 & ": USER FOUND")
51: Set objRecipient = GetObject("LDAP://" & strDN2) 52:
53: objRecipient.ProxyAddresses = arrProxyAddresses
54: objRecipient.put "mailnickname", strName
55: objRecipient.put "mail", strEmailAddr
56: ' objRecipient.MailEnable strEmailAddr
57: objRecipient.SetInfo
58: MsgBox("OK") 59: End If
60:
61: objContact.DeleteObject(0)
62:
63: objRecordset.Close
64: objRecordset2.Close
65:
66: Else
67: MsgBox(strName & ": NOT_FOUND")
68: End If
69:
70: objConnection.Close