How to add new mail address to AD
One of companies I take care of was bought by another company... I needed to add new primary mail (from name.surname@old_domain.cz to name.surname@new_domain.cz)
So I decided to use script for this. Here is the result:
Set myOU = GetObject("LDAP://OU=Uzivatele, DC=Old_Domain, DC=cz")
For each myUser in myOU
Set objRecipient = myUser
bIsFound = False
vProxyAddresses = objRecipient.ProxyAddresses
nProxyAddresses = UBound(vProxyAddresses)
i=0
Do While i <= nProxyAddresses
email = vProxyAddresses(i)
If InStr(mid(email,6),"@New_Domain.cz") Then
bIsFound = True
Exit Do
End If
If Left (email, 5) = "SMTP:" Then
vProxyAddresses(i) = "smtp:" & Mid(email,6)
MailIndex = InStr(mid(email,6),"@")
strNewProxyAddresses = "SMTP:" & Mid(email, 6, MailIndex - 1) & "@New_Domain.cz"
Wscript.Echo strNewProxyAddresses
End If
If vProxyAddresses(i) = strNewProxyAddresses Then
bIsFound = True
Exit Do
End If
i = i + 1
Loop
If Not bIsFound Then
ReDim Preserve vProxyAddresses(nProxyAddresses + 1)
vProxyAddresses(nProxyAddresses + 1) = strNewproxyAddresses
objRecipient.ProxyAddresses = vProxyAddresses
myUser.SetInfo
End If
Next
Heh, and it is working... It will take all users from specified OU, and if they dont have @new_domain.cz mail, it will take their actual primary mail, take first part (name.surname) and same new mail address in format first_part_of_actual_primary_mail@new_domain.com. And of course it will change current primary mail as normal :)
P.S.: Sorry for formating, looks like this blog system does not support [CODE][/CODE] :(