I don't know if this post is closed or not but I didn't see anyone comment on this script that ThePiriah posted. I like the layout allot better but me being a newbie with scripting I don't fully get all the code. When testing this script I'm getting an error of Line:100, Char:1, Error:Object required: 'txtUser'. I'm not sure what to put in those quotation marks if anything. I'm trying to use this script for my HR Dept to create users that will put them in the correct OU and set them up with a email address that has a specific format of the first four letters of the users first name and first four letters of users last name. For a total of eight characters and no more no less. I would also like an option to disable an account that would remove mailbox and hide the disabled account from global address list. I know this is allot to ask but I'm working on it using this base script. I would appreciate any input. Thanks.
<html>
<head>
<title>User Account Creation Form v2.0</title>
<HTA:APPLICATION
ID = "AccountCreationApp"
APPLICATIONNAME="Account Creation"
BORDER = "thin"
CAPTION = "yes"
RESIZE = "no"
ICON = "sprocket.ico"
SHOWINTASKBAR = "yes"
SINGLEINSTANCE = "yes"
SYSMENU = "yes"
WINDOWSTATE = "normal"
SCROLL = "yes"
SCROLLFLAT = "yes"
VERSION = "2.0"
INNERBORDER = "no"
SELECTION = "no"
MAXIMIZEBUTTON = "no"
MINIMIZEBUTTON = "yes"
NAVIGABLE = "yes"
CONTEXTMENU = "yes"
BORDERSTYLE = "normal">
</hta>
<style>
BODY
{
background-color: #E5ECF9;
font-family: Helvetica;
font-size: 8pt;
margin-top: 10px;
margin-left: 20px;
margin-right: 10px;
margin-bottom: 10px;
scrollbar-track-color: #E5ECF9;
scrollbar-3dlight-color: #E5ECF9;
scrollbar-arrow-color: #E5ECF9;
scrollbar-base-color: #E5ECF9;
scrollbar-darkshadow-color: #E5ECF9;
scrollbar-face-color: #E5ECF9;
scrollbar-highlight-color: #E5ECF9;
scrollbar-shadow-color: #E5ECF9
}
TD
{
font-family: Trebuchet MS;
font-size: 8pt;
}
LEGEND
{
font-family: Trebuchet MS;
font-size: 10pt;
}
SELECT
{
font-family: Trebuchet MS;
font-size: 8pt;
width:195px
}
INPUT
{
font-family: Trebuchet MS;
font-size: 8pt;
}
</style>
<script language="VBScript">
Dim defaultNC, BaseOU
defaultNC = GetObject("LDAP://RootDSE").Get("DefaultNamingContext")
BaseOU = "OU=Domain Clients," & defaultNC
Logpath ="C:\logs\"
Const FORAPPENDING = 8
sub window_onload
Dim x,y
x = (window.screen.width - 750) / 2
y = (window.screen.height - 700) / 2
If x < 0 Then x = 0
If y < 0 Then y = 0
window.resizeTo 765,600
window.moveTo x,y
end sub
Sub chkExch_OnClick()
If chkExch.checked = true Then
cbxExch.Disabled = 0
Else
cbxExch.Disabled = 1
End If
End Sub
Sub chkDL_OnClick()
If chkDL.checked = true Then
cbxDL.Disabled = 1
Else
cbxDL.Disabled = 0
End If
End Sub
' ## Start user account creation process ##
Sub CreateAccount
strUser = txtUser.Value
If strUser = "" Then
MsgBox "You are missing required fields.",64, "Alert"
Exit Sub
End If
strFirst = txtFirst.Value
If strFirst = "" Then
MsgBox "You are missing required fields.",64, "Alert"
Exit Sub
End If
strInitial = txtMiddle.Value
strLast = txtLast.Value
If strLast = "" Then
MsgBox "You are missing required fields.",64, "Alert"
Exit Sub
End If
strDisplay = UCase(Left(strLast, 1)) & LCase(Right(strLast, Len(strLast) - 1)) & " " _
& UCase(Left(strFirst, 1)) & LCase(Right(strFirst, Len(strFirst) - 1))
strTitle = txtTitle.Value
strOffice = cbxSite.Value
strDepartment = txtDepartment.Value
strCompany = txtCompany.Value
strManager = txtManager.Value
strCN = UCase(Left(strLast, 1)) & LCase(Right(strLast, Len(strLast) - 1)) & " " _
& UCase(Left(strFirst, 1)) & LCase(Right(strFirst, Len(strFirst) - 1))
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText = _
"<GC://" & defaultNC & ">;(&(objectCategory=Person)(objectClass=user)" & _
"(samAccountName=" & strUser & "));samAccountName;subtree"
Set objRecordSet = objCommand.Execute
If objRecordSet.RecordCount = 0 Then
Else
MsgBox "The User Account already exists.",48,"Alert"
Exit Sub
End If
objConnection.Close
Const FORWRITING= 2
Const ADS_UF_ACCOUNTDISABLE = 2
Const ADS_PROPERTY_UPDATE = 2
Const ADS_PROPERTY_APPEND = 3
' ## Determine if Creation of User Mailbox required ##
If chkExch.checked = "True" And cbxExch.value = "cbxExchAlert" Then
MsgBox "You must select either a Server/Mailstore or " & vbcrlf _
& "de-select the 'Create Mailbox' checkbox." ,64, "Alert"
Exit Sub
End If
' ## Add user to required Distribution List ##
If chkDL.checked ="True" And cbxDL.value = "cbxDLAlert" Then
MsgBox "You must select a Distribution List or " & vbcrlf _
& "de-select the 'Distribution List' checkbox." ,64, "Alert"
Exit Sub
End If
' ## Ensure users site/office selected ##
If cbxSite.Value = "cbxOfficeAlert" Then
MsgBox "You must select the users office.",64, "Alert"
Exit Sub
End If
Select Case cbxSite.Value
Case "Birmingham"
strOffice = "Birmingham"
strLDAPdn = "OU=_ Birmingham," & BaseOU
strUserServer = "Northsea"
Case "Exeter"
strOffice = "Exeter"
strLDAPdn = "OU=_ Exeter," & BaseOU
strUserServer = "Cluster"
Case "Hatfield"
strOffice = "Hatfield"
strLDAPdn = "OU=_ Hatfield," & BaseOU
strUserServer = "Data1Hat"
Case "Leeds"
strOffice = "Leeds"
strLDAPdn = "OU=_ Leeds," & BaseOU
strUserServer = "Sagat"
Case "Newcastle"
strOffice = "Newcastle"
strLDAPdn = "OU=_ Newcastle," & BaseOU
strUserServer = "fluorine" <!-- Arsenic -->
Case "Other"
strOffice = "Other"
strLDAPdn = "OU=_ Other," & BaseOU
strUserServer = "fluorine"
Case "Other"
strOffice = "Other"
strLDAPdn = "OU=_ Oxford," & BaseOU
strUserServer = "Data1Oxf"
Case "Paddington"
strOffice = "Paddington"
strLDAPdn = "OU=_ Paddington," & BaseOU
strUserServer = "Data1Pad"
Case "Portland House"
strOffice = "Portland"
strLDAPdn = "OU=_ Portland House," & BaseOU
strUserServer = "Data1Pot"
Case "Redditch"
strOffice = "Redditch"
strLDAPdn = "OU=_ Redditch," & BaseOU
strUserServer = "Red-DC"
Case "Richmond House"
strOffice = "Richmond House"
strLDAPdn = "OU=_ Richmond House," & BaseOU
strUserServer = "Data1Rich"
Case "Slough"
strOffice = "Slough"
strLDAPdn = "OU=_ Slough," & BaseOU
strUserServer = "Data1Slo"
Case "Tavistock"
strOffice = "Tavistock House"
strLDAPdn = "OU=_ Tavistock House," & BaseOU
strUserServer = "fluorine" <!-- maverick -->
Case "Winchester"
strOffice = "Winchester"
strLDAPdn = "OU=_ Winchester," & BaseOU
strUserServer = "fluorine"
End Select
Set objOU = GetObject("LDAP://" & strLDAPdn)
Set objUser = objOU.Create("User", "cn=" & strCN)
objUser.Put "sAMAccountName", LCase(strUser)
objUser.SetInfo
objUser.Put "givenName", UCase(Left(strFirst, 1)) & LCase(Right(strFirst, Len(strFirst) - 1))
If strInitial <> "" Then
objUser.Put "initials", UCase(Left(strInitial, 1)) & LCase(Right(strInitial, Len(strInitial) - 1))
End If
objUser.Put "sn", UCase(Left(strLast, 1)) & LCase(Right(strLast, Len(strLast) - 1))
objUser.Put "displayName", UCase(Left(strLast, 1)) & LCase(Right(strLast, Len(strLast) - 1)) & " " _
& UCase(Left(strFirst, 1)) & LCase(Right(strFirst, Len(strFirst) - 1))
If strTitle <> "" Then
objUser.put "title", strTitle
End If
If strDepartment <> "" Then
objUser.put "department", strDepartment
End If
If strCompany <> "" Then
objUser.put "company", strCompany
End If
If strManager <> "" Then
objUser.put "manager", strManager
End If
objUser.put "physicalDeliveryOfficeName", strOffice
objUser.put "description", strTitle
objUser.Put "userPrincipalName", LCase(strUser) & "@" & defaultNC
objUser.SetPassword "welcome"
objUser.Put "pwdLastSet", 0
intUAC = objUser.Get("userAccountControl")
If intUAC And ADS_UF_ACCOUNTDISABLE Then
objUser.Put"userAccountControl", intUAC Xor ADS_UF_ACCOUNTDISABLE
End If
objUser.SetInfo
' ## Add Users to selected groups ##
If chkGrpOne.Checked Then
Set objGroup = GetObject _
("LDAP://cn=NPFIT,OU=Other Mail-enabled Security Groups,OU=Groups,OU=__ Migration Staging," & BaseOU)
objGroup.PutEx ADS_PROPERTY_APPEND, _
"member", Array("cn=" & strCN & "," & strLDAPdn)
objGroup.SetInfo
End If
If chkGrpTwo.Checked Then
Set objGroup = GetObject _
("LDAP://cn=Share - NPSO Files,OU=File Share Access,OU=Groups,OU=__ Migration Staging," & BaseOU)
objGroup.PutEx ADS_PROPERTY_APPEND, _
"member", Array("cn=" & strCN & "," & strLDAPdn)
objGroup.SetInfo
End If
If chkGrpThree.Checked Then
Set objGroup = GetObject _
("LDAP://cn=Shared Data,OU=Universal Security,OU=Groups (Don't Migrate?),OU=_ Migration Staging - DO NOT MOVE OR ADD OBJECTS HERE!," & defaultNC)
objGroup.PutEx ADS_PROPERTY_APPEND, _
"member", Array("cn=" & strCN & "," & strLDAPdn)
objGroup.SetInfo
End If
' ## Create User Mailbox Process ##
If ChkExch.Checked Then
Call CreateMailbox (strCN,strLDAPdn)
End If
' ## Create User Folder Process ##
If chkUserFolder.Checked Then
Call CreateUserFolder (strUser,strUserServer)
End If
' ## Writes entry into logfile ##
If chkLogging.Checked Then
WriteLog("Account Created: " & DateToStr() & ", " & Time() & ", " & strUser _
& ", " & strFirst & " " & strLast & ", " & strOffice)
End If
' ## Reloads Page on completion of User Creation ##
Location.Reload(True)
MsgBox "User Successfully Created.",64, "Alert - User Creation Successful."
End Sub
Sub CreateMailbox (strCN,strLDAPdn)
' ## Start Mail Account Creation Process ##
Dim oIADSUser
Dim strMStore
Set oIADSUser = GetObject("LDAP://cn=" & strCN & "," & strLDAPdn)
' ## EXCHPE MAIL STORES ##
Select Case cbxExch.Value
Case "EXCHPEA2G"
strExchServer = "EXCHPE"
strMStore = "A2G"
strStoreGP = "2nd Storage Group"
Case "EXCHPEH2M"
strExchServer = "EXCHPE"
strMStore = "H2M"
strStoreGP = "2nd Storage Group"
Case "EXCHPEN2S"
strExchServer = "EXCHPE"
strMStore = "N2S"
strStoreGP = "3rd Storage Group"
Case "EXCHPET2Z"
strExchServer = "EXCHPE"
strMStore = "T2Z"
strStoreGP = "3rd Storage Group"
' ## EXCHAQ2 MAIL STORES ##
Case "EXCHAQ2A2G"
strExchServer = "EXCHAQ2"
strMStore = "A2G"
strStoreGP = "2nd Storage Group"
Case "EXCHAQ2H2M"
strExchServer = "EXCHAQ2"
strMStore = "H2M"
strStoreGP = "2nd Storage Group"
Case "EXCHAQ2N2S"
strExchServer = "EXCHAQ2"
strMStore = "N2S"
strStoreGP = "3rd Storage Group"
Case "EXCHAQ2T2Z"
strExchServer = "EXCHAQ2"
strMStore = "T2Z"
strStoreGP = "3rd Storage Group"
Case "ODIN"
strExchServer = "ODIN"
strMStore = "Mailbox Store (ODIN)"
strStoreGP = "First Storage Group"
End Select
oIADSUser.CreateMailbox ("LDAP://CN=" & strMStore & ",CN=" & strStoreGP & ",CN=InformationStore,CN=" & strExchServer & ",CN=Servers,CN=NHSIA,CN=Administrative Groups,CN=NHS,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=nhsia,DC=nhs,DC=uk")
oIADSUser.SetInfo
' ## End of Mail Account Creation Process ##
End Sub
Sub CreateUserFolder (strUser,strUserServer)
' ## If Users Home Server is flourine then Users home drive has to be created manually ##
If strUserServer = "fluorine" Then
MsgBox "User folder must be created manually.",16, "Alert - Folder Creation Unsuccessful."
Exit Sub
End If
' ## Create the Users home folder on respective server ##
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("\\" & strUserServer & "\users")
' ## Create users home folder ##
If objFSO.FolderExists("\\" & strUserServer & "\users\" & strUser) = False Then
objFSO.CreateFolder("\\" & strUserServer & "\users\" & LCase(strUser))
End If
' ## Assign user change NTFS permissions on home drives ##
Set objShell = CreateObject("Wscript.Shell")
strUserFolder = "\\" & strUserServer & "\users\" & strUser
objShell.Run ("SetACL.exe -on """ & strUserFolder & """ -ot file -actn ace " & "-ace ""n:npfit.nhs.uk\" & strUser & ";p:change""")
End Sub
Sub WriteLog (strMessage)
Dim LogFile
Dim fs
Dim fsOut
Logfile = Logpath & "AccountCreation.log"
Set fs = CreateObject("Scripting.FileSystemObject")
Set fsOut = fs.OpenTextFile(LogFile, ForAppending, True)
fsOut.WriteLine (strMessage)
fsOut.Close
End Sub
Function DateToStr()
DateToStr = DatePart("d",Now) & "/" & DatePart("m",Now) & "/" & DatePart("yyyy",Now)
End Function
' ## Reloads Page on pressing [Clear Form] ##
Sub Reload
Location.Reload(True)
End Sub
' ## Closes page on pressing [Exit] ##
Sub CloseForm
Window.Close
End Sub 'CloseForm
Sub About()
On Error Resume Next
strAbout="User Account Creation Form v2.0" & VbCrLf
strAbout= strAbout & "____________________________" & vbTab & VbCrLf & VbCrLf
strAbout=strAbout & " NHS Connecting For Health" & VbCrLf & VbCrLf
strAbout=strAbout & " Author: Darren Marsden" & VbCrLf
strAbout=strAbout & " Date: 31 July 2005" & vbcrlf & vbcrlf
strAbout= strAbout & "____________________________" & VbCrLf & VbCrLf
MsgBox strAbout,vbOKOnly+vbInformation,"About"
End Sub
</script>
</head>
<body>
<!-- Start Of Main Table -->
<table width="710" border="0" cellspacing="0" CellSpacing="0">
<tr><td width="350" Valign="top">
<!-- LHS Of Main Table -->
<table border="0" cellspacing="0" CellSpacing="0">
<tr><td width="350">
<!-- Username/Shortcode -->
<table border="0" cellspacing="0" CellSpacing="0" width="350">
<tr><td valign="top" colspan="3"><fieldset><legend><b>Username/Shortcode</b></legend>
<table border="0" cellpadding="3" width="350">
<tr><td width="110">Shortcode:</td><td><input type="text"
name="txtUser" style="width:195px"></td><td> </td></tr>
<tr><td>First Name: </td><td><input type="text" name="txtFirst" style="width:195px"></td><td
width="50"> </td></tr>
<tr><td>Middle Initial: </td><td><input type="text" name="txtMiddle" style="width:195px"></td>
<td>(Optional)</td></tr>
<tr><td>Last Name: </td><td><input type="text" name="txtLast" style="width:195px"></td><td> </td></tr>
</table><p></fieldset></table>
<!-- End of Username/Shortcode -->
<!-- User Account Properties -->
<table border="0" cellpadding="0" cellspacing="0" width="350">
<tr><td valign="top" colspan="3"><fieldset><legend><b>User Account Properties</b></legend>
<table border="0" cellpadding="3" width="350">
<tr>
<td width="110">Job Title:</td><td><input type="text" name="txtTitle" style="width:195px"></td><td> </td>
</tr>
<tr><td>Office: </td>
<td align="right">
<select size="1" name="cbxSite">
<option value="Birmingham">Birmingham</option>
<option value="Exeter">Exeter</option>
<option value="Hatfield">Hatfield</option>
<option value="Leeds">Leeds</option>
<option value="Newcastle">Newcastle</option>
<option value="Other">Other</option>
<option value="Oxford">Oxford</option>
<option value="Paddington">Paddington</option>
<option value="Portland">Portland House</option>
<option value="Redditch">Redditch</option>
<option value="Richmond">Richmond House</option>
<option value="Slough">Slough</option>
<option value="Tavistock">Tavistock House</option>
<option value="Winchester">Winchester</option>
<option selected value="cbxOfficeAlert">-- Select Users Office --</option>
</select></td>
<td> </td>
</tr>
<tr>
<td>Department: </td><td><input type="text" name="txtDepartment" style="width:195px"></td><td width="50"> </td>
</tr>
<tr>
<td>Company: </td><td><input type="text" name="txtCompany" value="NHS Connecting For Health" style="width:195px"></td><td> </td>
</tr>
<tr>
<td>Manager: </td><td><input type="text" name="txtManager" style="width:195px" disabled="True"></td><td>(Optional)</td>
</tr>
</table><p></fieldset></table>
<!-- End of User Account Properties -->
<!-- Group Membership -->
<table border="0" cellspacing="0" CellSpacing="0" width="350">
<tr>
<td valign="top" colspan="3"><fieldset><legend><b>Group Membership</b></legend>
<table border="0" cellpadding="3" width="350">
<tr>
<td width="150"><b>Group Name</b></td><td width="200" align="middle">Select to add user to group(s)</td>
</tr>
<tr>
<td width="150">NPFIT (File Access)</td><td width="200" align="middle"><input type="checkbox" name="chkGrpOne" checked="true"></td>
</tr>
<tr>
<td width="150">Share - NPSO Files</td><td width="200" align="middle"><input type="checkbox" name="chkGrpTwo" checked="true"></td>
</tr>
<tr>
<td width="150">Shared Data <font size="3" color="red"><b>*</b></font></td><td width="200" align="middle"><input type="checkbox" name="chkGrpThree" disabled="true"></td>
</tr>
</table><p></fieldset></table>
<!-- End of Group Membership -->
<!-- End of LHS Of Main Table -->
</td></tr></table>
</td>
<td width="350" Valign="top">
<!-- RHS Of Main Table -->
<table border="0" cellspacing="0" CellSpacing="0">
<tr><td width="350">
<!-- Create User Mail Account -->
<table border="0" cellspacing="0" CellSpacing="0" width="350">
<tr><td valign="top" colspan="3"><fieldset><legend><b>User Mail Account</b></legend>
<table border="0" cellpadding="3" width="350">
<tr>
<td width="300">Create user mailbox?</td><td width="50" align="middle"><input type="checkbox" name="chkExch" checked="true"></td>
</tr></table>
<table border="0" cellpadding="3" width="350">
<tr>
<td width="125">Server/Mailstore: </td>
<td align="right"><select size="1" name="cbxExch">
<option value="EXCHPEA2G">EXCHPE [ A2G ]</option>
<option value="EXCHPEH2M">EXCHPE [ H2M ]</option>
<option value="EXCHPEN2S">EXCHPE [ N2S ]</option>
<option value="EXCHPET2Z">EXCHPE [ T2Z ]</option>
<option value="EXCHAQ2A2G">EXCHAQ2 [ A2G ]</option>
<option value="EXCHAQ2H2M">EXCHAQ2 [ H2M ]</option>
<option value="EXCHAQ2N2S">EXCHAQ2 [ N2S ]</option>
<option value="EXCHAQ2T2Z">EXCHAQ2 [ T2Z ]</option>
<option value="ODINMS">ODIN</option>
<option selected value="cbxExchAlert">-- Select Server/Mailstore --</option>
</select></td>
</tr>
</table><p></fieldset></table>
<!-- End of Create User Mailbox -->
<!-- Add to Distribution Lists -->
<table border="0" cellspacing="0" CellSpacing="0" width="350">
<tr><td valign="top" colspan="3"><fieldset><legend><b>Distribution Lists</b></legend>
<table border="0" cellpadding="3" width="350">
<tr>
<td width="300">Add user to Distribution List?</td><td width="50" align="middle"><input type="checkbox" name="chkDL" disabled="true"></td>
</tr></table>
<table border="0" cellpadding="3" width="350">
<tr><td width="125">Distribution List: <font size="3" color="red"><b>*</b></font></td>
<td align="right"><select size="1" name="cbxDL" disabled="true">
<option value="DLBirmingham">Aqueous II</option>
<option value="DLExeter">DL Exeter</option>
<option value="DLOxford">DL Oxford</option>
<option value="DLPortland ">DL Portland</option>
<option value="DLHatfield">DL Hatfield</option>
<option value="DLHuntingdon">DL Huntingdon</option>
<option value="DLNewcastle">DL Newcastle</option>
<option value="DLPaddington">DL Paddington</option>
<option value="DLSlough">DL Slough</option>
<option value="DLTavistock">DL Tavistock House</option>
<option selected value="cbxDLAlert">-- Select Distribution List --</option>
</select></td>
</tr>
</table><p></fieldset></table>
<!-- End of Add to Distribution Lists -->
<!-- Create User Home Directory -->
<table border="0" cellspacing="0" CellSpacing="0" width="350">
<tr><td valign="top" colspan="3"><fieldset><legend><b>User Home Directory</b></legend>
<table border="0" cellpadding="3" width="350">
<tr>
<td width="300">Create User Home Directory?</td><td width="50" align="middle">
<input type="checkbox" name="chkUserFolder" checked="true">
</td></tr>
</table><p></fieldset></table>
<!-- End Of Create User Home Directory -->
<!-- Enable Logging -->
<table border="0" cellspacing="0" CellSpacing="0" width="350">
<tr><td valign="top" colspan="3"><fieldset><legend><b>Enable Logging</b></legend>
<table border="0" cellpadding="3" width="350">
<tr>
<td width="300">Enable Logging?</td><td width="50" align="middle">
<input type="checkbox" name="chkLogging" checked="true">
</td></tr>
</table><p></fieldset></table>
<!-- End Of Enable Logging -->
<table border="0" cellspacing="0" cellpadding="0" width="350" height="147">
<tr>
<td valign="top">
<!-- Blank Table for future additions/features -->
<b>NOTE:</b> Items marked with <font size="3" color="red"><b>*</b></font> are disabled until the migration is complete.
</td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="0" width="350">
<tr>
<td align="right" valign="bottom">
<input type="button" value=" About " onclick="About">
<input type="button" value="Clear Form" onclick="Reload" title=" Click to Clear Form ">
<input type="button" value=" Submit " onClick="CreateAccount" title=" Click to Create User Account ">
<input type="button" value=" Exit " onclick="CloseForm" title=" Click to Exit Form ">
</td></tr>
</table>
<!-- End of RHS Of Main Table -->
</td></tr></table>
</td></tr></table>
<!-- End Of Main Table -->
</body>
</html>
<message edited by shanfont on Tuesday, February 27, 2007 7:07 AM>