I have written a script that creates new user accounts in the active directory. Part of the script creates a username from the details that have been input using the first 6 letters of the surname and the first initial of the firstname. For example Peter Richards would become richarp. I would like first to check that the username is not already being used which I have managed however there are a variety of locations where the user name could be which is where I am my script has currently ground to a halt.
I propose to use an array of locations and assume that I would need to loop through the array but have tried a couple of different ways none of which seem to work. the script that I have so far is this:
firstname=inputbox("Type the users first name")
if firstname =""then
wscript.echo "You didn't enter a recognised name"
wscript.quit
end if
lastname1=inputbox("type the users surname")
if lastname1 =""then
wscript.echo "You didn't enter a recognised surname"
wscript.quit
end if
lastname= UCase(lastname1)
initial = LCase(Left(firstName, 1))
username1 = LCase(left(lastName,6))
username = username1 & initial
bothName = firstName & " " & lastName
strdisplayname = lastname & " " & firstname & " -Domain"
strdisplayname1 = lastname & ", " & firstname & " -Domain"
Set objDomain = GetObject("LDAP://" & strldap)'this variable is the path to the container where the user will be created
For Each objUser In objDomain
If(objUser.sAMAccountName) = (username) Then
wscript.echo "Username : " & username & " is already being used in this container."
initial = LCase(Left(firstName, 2))
username1 = LCase(left(lastName,6))
username = username1 & initial
Exit For
End If
Next
wscript.echo "Your user has been given the following username: " & username
A problem has also arisen in that although the usernames that we now use are all lowercase previous usernames were a mixture of upper and lower laces letters and searches on the active directory have not yielded results even when looking in the correct container. Could anybody point me in the right direction? To deal with the array my most recent attempte is:
dim names(4)
names(0)="OU= container1"
names(1)="OU= container2"
names(2)="OU= container3"
names(3)="OU= container4"
for i= 0 to 3
Set objDomain = GetObjects("LDAP://" & names()+i)
For Each objUser In objDomain
If(objUser.sAMAccountName) = (username) Then
wscript.echo "Username : " & username & " is already being used in this container."
initial = LCase(Left(firstName, 2))
username1 = LCase(left(lastName,6))
username = username1 & initial
Exit For
End If
Next
next
But this doesn't work!
I propose to use an array of locations and assume that I would need to loop through the array but have tried a couple of different ways none of which seem to work. the script that I have so far is this:
firstname=inputbox("Type the users first name")
if firstname =""then
wscript.echo "You didn't enter a recognised name"
wscript.quit
end if
lastname1=inputbox("type the users surname")
if lastname1 =""then
wscript.echo "You didn't enter a recognised surname"
wscript.quit
end if
lastname= UCase(lastname1)
initial = LCase(Left(firstName, 1))
username1 = LCase(left(lastName,6))
username = username1 & initial
bothName = firstName & " " & lastName
strdisplayname = lastname & " " & firstname & " -Domain"
strdisplayname1 = lastname & ", " & firstname & " -Domain"
Set objDomain = GetObject("LDAP://" & strldap)'this variable is the path to the container where the user will be created
For Each objUser In objDomain
If(objUser.sAMAccountName) = (username) Then
wscript.echo "Username : " & username & " is already being used in this container."
initial = LCase(Left(firstName, 2))
username1 = LCase(left(lastName,6))
username = username1 & initial
Exit For
End If
Next
wscript.echo "Your user has been given the following username: " & username
A problem has also arisen in that although the usernames that we now use are all lowercase previous usernames were a mixture of upper and lower laces letters and searches on the active directory have not yielded results even when looking in the correct container. Could anybody point me in the right direction? To deal with the array my most recent attempte is:
dim names(4)
names(0)="OU= container1"
names(1)="OU= container2"
names(2)="OU= container3"
names(3)="OU= container4"
for i= 0 to 3
Set objDomain = GetObjects("LDAP://" & names()+i)
For Each objUser In objDomain
If(objUser.sAMAccountName) = (username) Then
wscript.echo "Username : " & username & " is already being used in this container."
initial = LCase(Left(firstName, 2))
username1 = LCase(left(lastName,6))
username = username1 & initial
Exit For
End If
Next
next
But this doesn't work!