Provisioning Hosted Exchange Users from a Web Page
Originally published July 22, 2005
I wrote last year, in this article, about using a script to provision a hosted Exchange user, and that works well.
Well, I should say, it works well for me. The other folks in the office who have to provision Exchange users, and whose mind doesn't work quite the same way mine does, think that it was unfriendly and difficult to use (they generally stop saying that when I show them how to do it all manually! -- but they still complain).
So, finally, I've put it into a web page. I did this for several reasons: complaints from these folks, the book I'm writing (I needed to proceduralize lots of stuff), and because of a permissions question that arose from readers of the original blog article.
To cut to the chase, you can download the code from: http://www.TheEssentialExchange.com/blogs/michael/Web-provision-2005-07-22.zip.
There were actually two interesting challenges for me. First, I'm not a web programmer anymore, and I had to discover how to do some things without duplicating lots and lots of code between Javascript and VBscript. Secondly, the biggest problem that I had to solve was getting data from Active Directory (which code was run at the server, prior to the webpage being rendered, known as RUNAT=Server) to the client for searches without an ActiveX component (after the webpage was displayed and dependent on user interactions, known as RUNAT=Client).
I learned quite a bit about mixing javascript and vbscript in a single webpage. Then, I threw all of that out, and decided to use vbscript only. It turned out to be much more efficient and short. This required that I use a feature I was previously unaware of in Internet Explorer (and I have no idea if it's available in other browsers) called “event scripts”.
Using event scripts let me do things like this to modify a form-element:
<input name="lastname" maxlength=25 size=25>
<script event="onblur" for="lastname" language="vbscript">
Dim strLast, strFirst, str, strPass, strChar
Dim i, j
' build a suggestion for the account name
strLast = Trim (document.buildexch.lastname.value)
strFirst= Trim (document.buildexch.firstname.value)
If (Len (strFirst) > 0) And (Len (strLast) > 0) Then
str = Left (strFirst, 1) & strLast
i = Len (str)
document.buildexch.user.value = str
End If
</script>
Granted, you can do similar things with a javascript “onblur='call-function();'”, but this let me stay in vbscript.
Interestingly enough, I had started down the mixed-script route because I had thought that the full DOM (document object model) required javascript. But I was incorrect in that. Everything is available in vbscript as well.
To solve the second problem, I used hidden form fields along with ASP to generate the content of those form fields. Therefore there are several things like this:
<INPUT TYPE=HIDDEN NAME=“stroulist“ VALUE=”domain1.com;domain2.com;domain3.com....”>
that are used to pass small data tables from the backend to the client. These are used in the client-side script in order to validate information and provide suggestions and choices to the end-user.
Neither of these solutions are rocket science, and I'm certain that experienced developers already knew all about these. They are new to me. :-)
To set this up, simply create a virtual directory off the Default Web Site on an Exchange Server (or any server where the Exchange System Management tools are installed). That particular virtual directory needs to have Anonymous access disabled, as shown in this picture:

I also recommend that you disable Basic authentication, as shown in this picture, but that is simply a preference of mine.
The user that is able to create an Exchange user must (assuming no special delegated permissions exist) be member of the Domain Admins security group (from ADUC).
The lib\constants.asp file has the items that you may need to modify to make this work in your environment. Note that the script presumes an environment, as described here. However, the code is quite general purpose, except for the dependence in a few places on OU_HOSTING.
The lib files are just code libraries, that I often reuse for multiple projects, slightly modified to work with ASP files instead of VBS or WSF files.
So, then enter http://server-name/prov/exch.asp and you should be good to go.
Enjoy!