'==========================================================================
'
' NAME: FixX500.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
' DATE : 7/16/2009
' COPYRIGHT © 2009, All Rights Reserved
'
' COMMENT: Add an X500 address to a user account to ensure user can
' reply to old mail after being moved to a new Exchange group.
'
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
' ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED To
' THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
' PARTICULAR PURPOSE.
'
' IN NO EVENT SHALL THE SPIDER'S PARLOR AND/OR ITS RESPECTIVE SUPPLIERS
' BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
' DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
' WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
' ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
' OF THIS CODE OR INFORMATION.
'
'==========================================================================
On Error Resume Next
Dim qQuery, objConnection, objCommand, objRecordSet
Dim oRootDSE, strDomain, objUser, addressArray
Const ADS_PROPERTY_APPEND = 3
x500Base = "/o=ExampleAB/ou=Organizationalunit1/cn=Recipients/cn="
Set oRootDSE = GetObject("LDAP://rootDSE")
strDomain = oRootDSE.get("defaultNamingContext")
' other categories = computer, user, printqueue, group
qQuery = "<LDAP://" & strDomain &">;" & _
"(objectCategory=person)" & _
";sAMAccountName,distinguishedName;subtree"
'Perform our query of AD for user objects
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Open "Provider=ADsDSOObject;"
objCommand.ActiveConnection = objConnection
objCommand.CommandText = qQuery
Set objRecordSet = objCommand.Execute
While Not objRecordSet.EOF
'Bind to the user object
Set objUser = GetObject("LDAP://" & objRecordSet.Fields("distinguishedName"))
'Get the mail nickname
addressArray = objUser.proxyAddresses
For Each address In addressArray
If Left(address,5) = "SMTP:" Then
nicknameArray = Split(address,"@")
defaultSMTPNickname = Replace(nicknameArray(0),"SMTP:","")
End If
Next
'Add the X500 Address
objUser.PutEx ADS_PROPERTY_APPEND, "proxyAddresses", Array("X500:" & x500Base & defaultSMTPNickname)
objUser.SetInfo
objrecordset.MoveNext
Wend
objConnection.Close