I have created a user creation script. It reads user attributes from a text
file and creates one user at a time.
It basically runs like

While there are rows in the text file Do
read value1
read value2
read value3
read value4
do a whole bunch of stuff (set attirbutes, add users to groups, etc)
Loop

Let's say though that value2 must be exactly 6 digits in length. If not,
the script should fail creating this user account and move on to the next.
I thought of using Exit Do, but won't that end the script rather then moving
to the next user? Is there a way to do this. I just figure it would be
faster and make the most sense to stop the creation of the specific account
and move on to the next one.

Re: If Then Exit Do by Richard

Richard
Sat Jan 27 04:45:06 CST 2007

Jeremy Schubert wrote:

> I have created a user creation script. It reads user attributes from a
text
> file and creates one user at a time.
> It basically runs like
>
> While there are rows in the text file Do
> read value1
> read value2
> read value3
> read value4
> do a whole bunch of stuff (set attirbutes, add users to groups, etc)
> Loop
>
> Let's say though that value2 must be exactly 6 digits in length. If not,
> the script should fail creating this user account and move on to the next.
> I thought of using Exit Do, but won't that end the script rather then
moving
> to the next user? Is there a way to do this. I just figure it would be
> faster and make the most sense to stop the creation of the specific
account
> and move on to the next one.
>
>

I think an If/Then structure should work. You may need several nested
If/Then's. Example:

Do until objFile.AtEndOfStream
' Read a line from file.
strLine = Trim(objFile.ReadLine)
' Skip blank lines.
If (strLine <> "") Then
' Values delimited by ";", split into array of values.
arrValues = Split(strLine, ";")
' Do stuff only if length of second value is 6, and it is numeric.
If (Len(arrValues(1)) = 6) And (IsNumeric(arrValues(1)) = True) Then
' Do stuff.
Else
' Value is not 6 digits, alert user.
Wscript.Echo "Bad value in line: " & strLine
End If
End If
Loop

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab web site - http://www.rlmueller.net
--



Re: If Then Exit Do by Randy

Randy
Sat Jan 27 11:12:26 CST 2007


"Richard Mueller [MVP]" <rlmueller-NOSPAM@ameritech.NOSPAM.net> wrote in
message news:OFncxBgQHHA.1908@TK2MSFTNGP05.phx.gbl...
> Jeremy Schubert wrote:
>
>> I have created a user creation script. It reads user attributes from a
> text
>> file and creates one user at a time.
>> It basically runs like
>>
>> While there are rows in the text file Do
>> read value1
>> read value2
>> read value3
>> read value4
>> do a whole bunch of stuff (set attirbutes, add users to groups, etc)
>> Loop
>>
>> Let's say though that value2 must be exactly 6 digits in length. If not,
>> the script should fail creating this user account and move on to the
>> next.
>> I thought of using Exit Do, but won't that end the script rather then
> moving
>> to the next user? Is there a way to do this. I just figure it would be
>> faster and make the most sense to stop the creation of the specific
> account
>> and move on to the next one.
>>
>>
>
> I think an If/Then structure should work. You may need several nested
> If/Then's. Example:
>
> Do until objFile.AtEndOfStream
> ' Read a line from file.
> strLine = Trim(objFile.ReadLine)
> ' Skip blank lines.
> If (strLine <> "") Then
> ' Values delimited by ";", split into array of values.
> arrValues = Split(strLine, ";")
> ' Do stuff only if length of second value is 6, and it is numeric.
> If (Len(arrValues(1)) = 6) And (IsNumeric(arrValues(1)) = True)
> Then
> ' Do stuff.
> Else
> ' Value is not 6 digits, alert user.
> Wscript.Echo "Bad value in line: " & strLine
> End If
> End If
> Loop
>
> --
> Richard
> Microsoft MVP Scripting and ADSI
> Hilltop Lab web site - http://www.rlmueller.net
> --

When I have to sort out a good case from a lot of bad cases, here is what I
do. (I think I found this technique on this newsgroup a couple of years
ago.) Note that all of the values to be tested must be available before the
tests are made. Using pseudocode for the original question:

read value1
read value2
read value3
read value4
Select Case True
Case value1 = "garbage":
Case not value2 like "######"
Case value3 < goodvalue
Case value4 <> something
Case Else
do a whole bunch of stuff (set attributes, add users to groups,
etc)
End Select

This avoids nests of if-then-else.

In the pseudocode, and in much of what I need to do, the bad cases are
simply ignored. You could of course add code to any of the cases to report
errors or something else. But you cannot fall back into a subsequent case
without an additional wrapper.

This works well for me when I am looking for one specific kind of thing and
want to reject a lot of others.

Randy



Re: If Then Exit Do by Jeremy

Jeremy
Sat Jan 27 15:43:06 CST 2007

Richard and Randy, both your suggestions are very straight forward and
logical. I'll have to decide which one I want to use.

I ran the script today and it seems to work well except that it left the $
off the end of the home directory share listings in ADUC. So I'll probably
do what I'm used to doing. Select all the users in the OU and edit their
properties to clear the home directory share listing.. Then I'll redirect a
directory listing of the Users folder to a text file and will open that txt
file in Excel to make a script to add the proper home share path.

But I was wondering if there was an easier way to do it. For example, I
though after clearing all of their home shares listings (there home shares
by the way are comprised of their "\\server\CN-LastName$), I could then use
a line like \\server\%CN%-%lastname%$. Do either of you have a suggestion
for me?

Thanks,
Jeremy



Re: If Then Exit Do by Richard

Richard
Mon Jan 29 11:19:03 CST 2007

Jeremy wrote:

> Richard and Randy, both your suggestions are very straight forward and
> logical. I'll have to decide which one I want to use.
>
> I ran the script today and it seems to work well except that it left the $
> off the end of the home directory share listings in ADUC. So I'll
probably
> do what I'm used to doing. Select all the users in the OU and edit their
> properties to clear the home directory share listing.. Then I'll redirect
a
> directory listing of the Users folder to a text file and will open that
txt
> file in Excel to make a script to add the proper home share path.
>
> But I was wondering if there was an easier way to do it. For example, I
> though after clearing all of their home shares listings (there home shares
> by the way are comprised of their "\\server\CN-LastName$), I could then
use
> a line like \\server\%CN%-%lastname%$. Do either of you have a suggestion
> for me?

If a program can determine the new value from the old, it can be done in one
step. A program can enumerate all users, retrieve the old value, determine
the new value, assign the new value, and save. To determine the new value
for the homeDirectory attribute, the program has the old value, plus the
values of sAMAccountName, cn, givenName, sn, and all other attributes to
work with.

To enumerate users, you can either enumerate the user objects in a
container/OU, or use ADO. ADO can retrieve any attribute values for all
users. Because ADO cannot modify, you would also retrieve distinguishedName,
so you can bind to the user objects to make the changes.

If I understand, the program would determine "\\server" from the old value
for homeDirectory, then use the values for cn (Common Name) and sn (last
name) to construct the new value. Are you sure you don't want to use
sAMAccountName (the NT name of the user, also called the pre-Windows 2000
logon name) instead of cn? sAMAccountName is unique in the domain, while
Common Name need only be unique in the container/OU. There can be several
users with the same value for cn.

For information on using ADO, see this link:

http://www.rlmueller.net/ADOSearchTips.htm

Otherwise, if this approach is not feasible, I have sample programs that
update profilePath for users according to the information in an Excel
spreadsheet. This first example identifies users by Distinguished Name:

http://www.rlmueller.net/UpdateUserProfile.htm

This second example is the same, but identifies users by sAMAccountName:

http://www.rlmueller.net/UpdateUserProfile2.htm

Either program could be modified to assign values to homeDirectory instead
of profilePath.

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab web site - http://www.rlmueller.net
--



Re: If Then Exit Do by Jeremy

Jeremy
Mon Jan 29 19:05:56 CST 2007


"Richard Mueller [MVP]" <rlmueller-NOSPAM@ameritech.NOSPAM.net> wrote in
message news:%23oREJn8QHHA.1200@TK2MSFTNGP02.phx.gbl...
> Jeremy wrote:
>
>> Richard and Randy, both your suggestions are very straight forward and
>> logical. I'll have to decide which one I want to use.
>>
>> I ran the script today and it seems to work well except that it left the
>> $
>> off the end of the home directory share listings in ADUC. So I'll
> probably
>> do what I'm used to doing. Select all the users in the OU and edit their
>> properties to clear the home directory share listing.. Then I'll
>> redirect
> a
>> directory listing of the Users folder to a text file and will open that
> txt
>> file in Excel to make a script to add the proper home share path.
>>
>> But I was wondering if there was an easier way to do it. For example, I
>> though after clearing all of their home shares listings (there home
>> shares
>> by the way are comprised of their "\\server\CN-LastName$), I could then
> use
>> a line like \\server\%CN%-%lastname%$. Do either of you have a
>> suggestion
>> for me?
>
> If a program can determine the new value from the old, it can be done in
> one
> step. A program can enumerate all users, retrieve the old value, determine
> the new value, assign the new value, and save. To determine the new value
> for the homeDirectory attribute, the program has the old value, plus the
> values of sAMAccountName, cn, givenName, sn, and all other attributes to
> work with.
>
> To enumerate users, you can either enumerate the user objects in a
> container/OU, or use ADO. ADO can retrieve any attribute values for all
> users. Because ADO cannot modify, you would also retrieve
> distinguishedName,
> so you can bind to the user objects to make the changes.
>
> If I understand, the program would determine "\\server" from the old value
> for homeDirectory, then use the values for cn (Common Name) and sn (last
> name) to construct the new value. Are you sure you don't want to use
> sAMAccountName (the NT name of the user, also called the pre-Windows 2000
> logon name) instead of cn? sAMAccountName is unique in the domain, while
> Common Name need only be unique in the container/OU. There can be several
> users with the same value for cn.
>
> For information on using ADO, see this link:
>
> http://www.rlmueller.net/ADOSearchTips.htm
>
> Otherwise, if this approach is not feasible, I have sample programs that
> update profilePath for users according to the information in an Excel
> spreadsheet. This first example identifies users by Distinguished Name:
>
> http://www.rlmueller.net/UpdateUserProfile.htm
>
> This second example is the same, but identifies users by sAMAccountName:
>
> http://www.rlmueller.net/UpdateUserProfile2.htm
>
> Either program could be modified to assign values to homeDirectory instead
> of profilePath.
>
> --
> Richard
> Microsoft MVP Scripting and ADSI
> Hilltop Lab web site - http://www.rlmueller.net
> --
>
>

Thank you Richard. I started today to complete a batch file to make the
changes using dsmod but I haven't got it working yet. But I'll also try out
your suggestions.
Thanks,
Jeremy



Re: If Then Exit Do by Jeremy

Jeremy
Mon Jan 29 19:49:30 CST 2007

Richard, re your CreateUserList3.vbs file. Can I modify the ldap path to
extract names only from one OU?
"Richard Mueller [MVP]" <rlmueller-NOSPAM@ameritech.NOSPAM.net> wrote in
message news:%23oREJn8QHHA.1200@TK2MSFTNGP02.phx.gbl...
> Jeremy wrote:
>
>> Richard and Randy, both your suggestions are very straight forward and
>> logical. I'll have to decide which one I want to use.
>>
>> I ran the script today and it seems to work well except that it left the
>> $
>> off the end of the home directory share listings in ADUC. So I'll
> probably
>> do what I'm used to doing. Select all the users in the OU and edit their
>> properties to clear the home directory share listing.. Then I'll
>> redirect
> a
>> directory listing of the Users folder to a text file and will open that
> txt
>> file in Excel to make a script to add the proper home share path.
>>
>> But I was wondering if there was an easier way to do it. For example, I
>> though after clearing all of their home shares listings (there home
>> shares
>> by the way are comprised of their "\\server\CN-LastName$), I could then
> use
>> a line like \\server\%CN%-%lastname%$. Do either of you have a
>> suggestion
>> for me?
>
> If a program can determine the new value from the old, it can be done in
> one
> step. A program can enumerate all users, retrieve the old value, determine
> the new value, assign the new value, and save. To determine the new value
> for the homeDirectory attribute, the program has the old value, plus the
> values of sAMAccountName, cn, givenName, sn, and all other attributes to
> work with.
>
> To enumerate users, you can either enumerate the user objects in a
> container/OU, or use ADO. ADO can retrieve any attribute values for all
> users. Because ADO cannot modify, you would also retrieve
> distinguishedName,
> so you can bind to the user objects to make the changes.
>
> If I understand, the program would determine "\\server" from the old value
> for homeDirectory, then use the values for cn (Common Name) and sn (last
> name) to construct the new value. Are you sure you don't want to use
> sAMAccountName (the NT name of the user, also called the pre-Windows 2000
> logon name) instead of cn? sAMAccountName is unique in the domain, while
> Common Name need only be unique in the container/OU. There can be several
> users with the same value for cn.
>
> For information on using ADO, see this link:
>
> http://www.rlmueller.net/ADOSearchTips.htm
>
> Otherwise, if this approach is not feasible, I have sample programs that
> update profilePath for users according to the information in an Excel
> spreadsheet. This first example identifies users by Distinguished Name:
>
> http://www.rlmueller.net/UpdateUserProfile.htm
>
> This second example is the same, but identifies users by sAMAccountName:
>
> http://www.rlmueller.net/UpdateUserProfile2.htm
>
> Either program could be modified to assign values to homeDirectory instead
> of profilePath.
>
> --
> Richard
> Microsoft MVP Scripting and ADSI
> Hilltop Lab web site - http://www.rlmueller.net
> --
>
>



Re: If Then Exit Do by Richard

Richard
Mon Jan 29 21:21:17 CST 2007

Yes. The ADO query in the example program is:

strQuery = "<LDAP://" & strDNSDomain & ">;" & strFilter _
& ";distinguishedName;subtree"

The first clause of the ADO query is the base of the search. In this case,
strDNSDomain is the Distinguished Name of the domain, so the entire domain
is searched. You could substitute the Distinguished Name of an OU. For
example:

strOU = "ou=Sales,dc=MyDomain,dc=com"

strQuery = "<LDAP://" & strOU & ">;" & strFilter _
& ";distinguishedName;subtree"

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab web site - http://www.rlmueller.net
--

"Jeremy Schubert" <jschubert@no*spam.shaw.ca> wrote in message
news:ubatbCBRHHA.4000@TK2MSFTNGP04.phx.gbl...
> Richard, re your CreateUserList3.vbs file. Can I modify the ldap path to
> extract names only from one OU?
> "Richard Mueller [MVP]" <rlmueller-NOSPAM@ameritech.NOSPAM.net> wrote in
> message news:%23oREJn8QHHA.1200@TK2MSFTNGP02.phx.gbl...
> > Jeremy wrote:
> >
> >> Richard and Randy, both your suggestions are very straight forward and
> >> logical. I'll have to decide which one I want to use.
> >>
> >> I ran the script today and it seems to work well except that it left
the
> >> $
> >> off the end of the home directory share listings in ADUC. So I'll
> > probably
> >> do what I'm used to doing. Select all the users in the OU and edit
their
> >> properties to clear the home directory share listing.. Then I'll
> >> redirect
> > a
> >> directory listing of the Users folder to a text file and will open that
> > txt
> >> file in Excel to make a script to add the proper home share path.
> >>
> >> But I was wondering if there was an easier way to do it. For example,
I
> >> though after clearing all of their home shares listings (there home
> >> shares
> >> by the way are comprised of their "\\server\CN-LastName$), I could
then
> > use
> >> a line like \\server\%CN%-%lastname%$. Do either of you have a
> >> suggestion
> >> for me?
> >
> > If a program can determine the new value from the old, it can be done in
> > one
> > step. A program can enumerate all users, retrieve the old value,
determine
> > the new value, assign the new value, and save. To determine the new
value
> > for the homeDirectory attribute, the program has the old value, plus the
> > values of sAMAccountName, cn, givenName, sn, and all other attributes to
> > work with.
> >
> > To enumerate users, you can either enumerate the user objects in a
> > container/OU, or use ADO. ADO can retrieve any attribute values for all
> > users. Because ADO cannot modify, you would also retrieve
> > distinguishedName,
> > so you can bind to the user objects to make the changes.
> >
> > If I understand, the program would determine "\\server" from the old
value
> > for homeDirectory, then use the values for cn (Common Name) and sn (last
> > name) to construct the new value. Are you sure you don't want to use
> > sAMAccountName (the NT name of the user, also called the pre-Windows
2000
> > logon name) instead of cn? sAMAccountName is unique in the domain, while
> > Common Name need only be unique in the container/OU. There can be
several
> > users with the same value for cn.
> >
> > For information on using ADO, see this link:
> >
> > http://www.rlmueller.net/ADOSearchTips.htm
> >
> > Otherwise, if this approach is not feasible, I have sample programs that
> > update profilePath for users according to the information in an Excel
> > spreadsheet. This first example identifies users by Distinguished Name:
> >
> > http://www.rlmueller.net/UpdateUserProfile.htm
> >
> > This second example is the same, but identifies users by sAMAccountName:
> >
> > http://www.rlmueller.net/UpdateUserProfile2.htm
> >
> > Either program could be modified to assign values to homeDirectory
instead
> > of profilePath.
> >
> > --
> > Richard
> > Microsoft MVP Scripting and ADSI
> > Hilltop Lab web site - http://www.rlmueller.net
> > --
> >
> >
>
>