Adding a Hosted Exchange User With VBScript - Patch 1
Originally published October 5, 2004
OK, I knew there would be bugs. :-) The first bug someone found is that the original script doesn't verify uniqueness of the User Principal Name. As I discuss elsewhere, Active Directory doesn't verify that either (which could be considered a bug in A/D, in my opinion).
Here is the fix.
In the CreateHostedUser subroutine, add this right after the DIM statements:
Dim strSearch
strSearch = "<LDAP://" & strNamingContext & ">;" & _
"(&(objectclass=user)(objectcategory=person)(userPrincipalName=" & strAccountName & "@" & strDomain & "));" & _
"userPrincipalName;subtree"
Call DoLDAPQuery (strSearch, Rs)
While Not Rs.EOF
e "*** Error: user already exists: " & strAccountName & "@" & strDomain
Rs.MoveNext
Call FinishLDAPQuery (Rs)
Exit Sub
WEnd