Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > auto add sutdents to AD 2008

Reply
Thread Tools Display Modes

auto add sutdents to AD 2008

 
 
nico
Guest
Posts: n/a

 
      06-11-2009
Hello,

I have a script that auto add's student to my AD for win2003 server.
for win2008server it does not work
I get errors

Any suggestions?

N.



' Author Guy Thomas http://computerperformance.co.uk/

' ------------------------------------------------------'
Option Explicit
Dim objRootLDAP, objContainer, objUser, objShell
Dim objExcel, objSpread, intRow
Dim strUser, strOU, strSheet
Dim strCN, strSam, strFirst, strLast, strPWD

' -------------------------------------------------------------'
' Important change OU= and strSheet to reflect your domain
' -------------------------------------------------------------'

strOU = "OU=Studenten ," ' Note the comma
strSheet = "D:\IT\users aanmaken\adduser.xls"

' Bind to Active Directory, Users container.
Set objRootLDAP = GetObject("LDAP://rootDSE")
Set objContainer = GetObject("LDAP://" & strOU & _
objRootLDAP.Get("defaultNamingContext"))

' Open the Excel spreadsheet
Set objExcel = CreateObject("Excel.Application")
Set objSpread = objExcel.Workbooks.Open(strSheet)
intRow = 3 'Row 1 often contains headings

' Here is the 'DO...Loop' that cycles through the cells
' Note intRow, x must correspond to the column in strSheet
Do Until objExcel.Cells(intRow,1).Value = ""
strSam = Trim(objExcel.Cells(intRow, 1).Value)
strCN = Trim(objExcel.Cells(intRow, 2).Value)
strFirst = Trim(objExcel.Cells(intRow, 3).Value)
strLast = Trim(objExcel.Cells(intRow, 4).Value)
strPWD = Trim(objExcel.Cells(intRow, 5).Value)

' Build the actual User from data in strSheet.
Set objUser = objContainer.Create("User", "cn=" & strCN)
objUser.sAMAccountName = strSam
objUser.givenName = strFirst
objUser.sn = strLast
objUser.SetInfo

' Separate section to enable account with its password
objUser.userAccountControl = 512
objUser.pwdLastSet = 0
objUser.SetPassword strPWD
objUser.SetInfo

intRow = intRow + 1
Loop
msgbox "Script met succes uitgevoerd",8,1
objExcel.Quit

WScript.Quit


' End of free example UserSpreadsheet VBScript.
 
Reply With Quote
 
 
 
 
Richard Mueller [MVP]
Guest
Posts: n/a

 
      06-11-2009

"nico" <> wrote in message
news:...
> Hello,
>
> I have a script that auto add's student to my AD for win2003 server.
> for win2008server it does not work
> I get errors
>
> Any suggestions?
>
> N.
>
>
>
> ' Author Guy Thomas http://computerperformance.co.uk/
>
> ' ------------------------------------------------------'
> Option Explicit
> Dim objRootLDAP, objContainer, objUser, objShell
> Dim objExcel, objSpread, intRow
> Dim strUser, strOU, strSheet
> Dim strCN, strSam, strFirst, strLast, strPWD
>
> ' -------------------------------------------------------------'
> ' Important change OU= and strSheet to reflect your domain
> ' -------------------------------------------------------------'
>
> strOU = "OU=Studenten ," ' Note the comma
> strSheet = "D:\IT\users aanmaken\adduser.xls"
>
> ' Bind to Active Directory, Users container.
> Set objRootLDAP = GetObject("LDAP://rootDSE")
> Set objContainer = GetObject("LDAP://" & strOU & _
> objRootLDAP.Get("defaultNamingContext"))
>
> ' Open the Excel spreadsheet
> Set objExcel = CreateObject("Excel.Application")
> Set objSpread = objExcel.Workbooks.Open(strSheet)
> intRow = 3 'Row 1 often contains headings
>
> ' Here is the 'DO...Loop' that cycles through the cells
> ' Note intRow, x must correspond to the column in strSheet
> Do Until objExcel.Cells(intRow,1).Value = ""
> strSam = Trim(objExcel.Cells(intRow, 1).Value)
> strCN = Trim(objExcel.Cells(intRow, 2).Value)
> strFirst = Trim(objExcel.Cells(intRow, 3).Value)
> strLast = Trim(objExcel.Cells(intRow, 4).Value)
> strPWD = Trim(objExcel.Cells(intRow, 5).Value)
>
> ' Build the actual User from data in strSheet.
> Set objUser = objContainer.Create("User", "cn=" & strCN)
> objUser.sAMAccountName = strSam
> objUser.givenName = strFirst
> objUser.sn = strLast
> objUser.SetInfo
>
> ' Separate section to enable account with its password
> objUser.userAccountControl = 512
> objUser.pwdLastSet = 0
> objUser.SetPassword strPWD
> objUser.SetInfo
>
> intRow = intRow + 1
> Loop
> msgbox "Script met succes uitgevoerd",8,1
> objExcel.Quit
>
> WScript.Quit
>
>
> ' End of free example UserSpreadsheet VBScript.


I don't see anything that would work in W2k3 but not W2k8, with the possible
exception of strong passwords. A minor point is that I would remove the
space before the comma in the following statement:

strOU = "OU=Studenten ," ' Note the comma

If the error is raised on the first SetInfo, then the problem is with cn,
sAMAccountName, givenName, or sn. The only way givenName or sn will raise an
error is if the value is blank. If this is possible, test for it and do not
assign if the value in the spreadsheet is blank. cn will raise an error if
it is not unique in the container, sAMAccountName will raise an error if it
is not unique in the domain.

I don't see how an error could be raised on the second SetInfo statement,
unless for some reason 512 is not allowed for userAccountControl. It might
help to use the AccountDisabled property method instead to enable the
account. For example

objUser.AccountDisabled = False

Finally, if the error is raised on the SetPassword statement, then your
password does not meet domain requirements, probably complexity.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


 
Reply With Quote
 
nico
Guest
Posts: n/a

 
      06-12-2009
R.,

the error is raised on the first SetInfo

neither givenName or sn is blank and
sAMAccountName is unique (the same as sn and givenname)

the error has as source "active directory"
and the (translated from dutch) error = access error


any suggestions?



Richard Mueller [MVP] schreef:
> "nico" <> wrote in message
> news:...
>> Hello,
>>
>> I have a script that auto add's student to my AD for win2003 server.
>> for win2008server it does not work
>> I get errors
>>
>> Any suggestions?
>>
>> N.
>>
>>
>>
>> ' Author Guy Thomas http://computerperformance.co.uk/
>>
>> ' ------------------------------------------------------'
>> Option Explicit
>> Dim objRootLDAP, objContainer, objUser, objShell
>> Dim objExcel, objSpread, intRow
>> Dim strUser, strOU, strSheet
>> Dim strCN, strSam, strFirst, strLast, strPWD
>>
>> ' -------------------------------------------------------------'
>> ' Important change OU= and strSheet to reflect your domain
>> ' -------------------------------------------------------------'
>>
>> strOU = "OU=Studenten ," ' Note the comma
>> strSheet = "D:\IT\users aanmaken\adduser.xls"
>>
>> ' Bind to Active Directory, Users container.
>> Set objRootLDAP = GetObject("LDAP://rootDSE")
>> Set objContainer = GetObject("LDAP://" & strOU & _
>> objRootLDAP.Get("defaultNamingContext"))
>>
>> ' Open the Excel spreadsheet
>> Set objExcel = CreateObject("Excel.Application")
>> Set objSpread = objExcel.Workbooks.Open(strSheet)
>> intRow = 3 'Row 1 often contains headings
>>
>> ' Here is the 'DO...Loop' that cycles through the cells
>> ' Note intRow, x must correspond to the column in strSheet
>> Do Until objExcel.Cells(intRow,1).Value = ""
>> strSam = Trim(objExcel.Cells(intRow, 1).Value)
>> strCN = Trim(objExcel.Cells(intRow, 2).Value)
>> strFirst = Trim(objExcel.Cells(intRow, 3).Value)
>> strLast = Trim(objExcel.Cells(intRow, 4).Value)
>> strPWD = Trim(objExcel.Cells(intRow, 5).Value)
>>
>> ' Build the actual User from data in strSheet.
>> Set objUser = objContainer.Create("User", "cn=" & strCN)
>> objUser.sAMAccountName = strSam
>> objUser.givenName = strFirst
>> objUser.sn = strLast
>> objUser.SetInfo
>>
>> ' Separate section to enable account with its password
>> objUser.userAccountControl = 512
>> objUser.pwdLastSet = 0
>> objUser.SetPassword strPWD
>> objUser.SetInfo
>>
>> intRow = intRow + 1
>> Loop
>> msgbox "Script met succes uitgevoerd",8,1
>> objExcel.Quit
>>
>> WScript.Quit
>>
>>
>> ' End of free example UserSpreadsheet VBScript.

>
> I don't see anything that would work in W2k3 but not W2k8, with the possible
> exception of strong passwords. A minor point is that I would remove the
> space before the comma in the following statement:
>
> strOU = "OU=Studenten ," ' Note the comma
>
> If the error is raised on the first SetInfo, then the problem is with cn,
> sAMAccountName, givenName, or sn. The only way givenName or sn will raise an
> error is if the value is blank. If this is possible, test for it and do not
> assign if the value in the spreadsheet is blank. cn will raise an error if
> it is not unique in the container, sAMAccountName will raise an error if it
> is not unique in the domain.
>
> I don't see how an error could be raised on the second SetInfo statement,
> unless for some reason 512 is not allowed for userAccountControl. It might
> help to use the AccountDisabled property method instead to enable the
> account. For example
>
> objUser.AccountDisabled = False
>
> Finally, if the error is raised on the SetPassword statement, then your
> password does not meet domain requirements, probably complexity.
>

 
Reply With Quote
 
Richard Mueller [MVP]
Guest
Posts: n/a

 
      06-12-2009
The sn and givenName attributes can be assigned anything, except a blank
string. If there is no value for either of these, just don't assign any
value.

If the value for sAMAccountName is unique in the domain, and the value of cn
is unique in the OU, then the only possible causes of the error I can think
of are:

1. You don't have permission to create user objects in the OU.
2. The sAMAccountName is more than 20 characters long.
3. The cn is more than 104 characters (if I remember correctly).
4. The sAMAccountName includes any of the following characters:
[ ] : ; | = + ? < > * "
5. If the value of the cn attribute includes any of the following
characters:
, \ # + < > ; " = /
or a leading or trailing space, then the character must be escaped using the
backslash, "\", escape character. For example, if the common name is "Smith,
Jim", then you must specify "Smith\, Jim". See this link for details:

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

Hopefully this accounts for the error.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--

"nico" <> wrote in message
news:...
> R.,
>
> the error is raised on the first SetInfo
>
> neither givenName or sn is blank and
> sAMAccountName is unique (the same as sn and givenname)
>
> the error has as source "active directory"
> and the (translated from dutch) error = access error
>
>
> any suggestions?
>
>
>
> Richard Mueller [MVP] schreef:
>> "nico" <> wrote in message
>> news:...
>>> Hello,
>>>
>>> I have a script that auto add's student to my AD for win2003 server.
>>> for win2008server it does not work
>>> I get errors
>>>
>>> Any suggestions?
>>>
>>> N.
>>>
>>>
>>>
>>> ' Author Guy Thomas http://computerperformance.co.uk/
>>>
>>> ' ------------------------------------------------------'
>>> Option Explicit
>>> Dim objRootLDAP, objContainer, objUser, objShell
>>> Dim objExcel, objSpread, intRow
>>> Dim strUser, strOU, strSheet
>>> Dim strCN, strSam, strFirst, strLast, strPWD
>>>
>>> ' -------------------------------------------------------------'
>>> ' Important change OU= and strSheet to reflect your domain
>>> ' -------------------------------------------------------------'
>>>
>>> strOU = "OU=Studenten ," ' Note the comma
>>> strSheet = "D:\IT\users aanmaken\adduser.xls"
>>>
>>> ' Bind to Active Directory, Users container.
>>> Set objRootLDAP = GetObject("LDAP://rootDSE")
>>> Set objContainer = GetObject("LDAP://" & strOU & _
>>> objRootLDAP.Get("defaultNamingContext"))
>>>
>>> ' Open the Excel spreadsheet
>>> Set objExcel = CreateObject("Excel.Application")
>>> Set objSpread = objExcel.Workbooks.Open(strSheet)
>>> intRow = 3 'Row 1 often contains headings
>>>
>>> ' Here is the 'DO...Loop' that cycles through the cells
>>> ' Note intRow, x must correspond to the column in strSheet
>>> Do Until objExcel.Cells(intRow,1).Value = ""
>>> strSam = Trim(objExcel.Cells(intRow, 1).Value)
>>> strCN = Trim(objExcel.Cells(intRow, 2).Value)
>>> strFirst = Trim(objExcel.Cells(intRow, 3).Value)
>>> strLast = Trim(objExcel.Cells(intRow, 4).Value)
>>> strPWD = Trim(objExcel.Cells(intRow, 5).Value)
>>>
>>> ' Build the actual User from data in strSheet.
>>> Set objUser = objContainer.Create("User", "cn=" & strCN)
>>> objUser.sAMAccountName = strSam
>>> objUser.givenName = strFirst
>>> objUser.sn = strLast
>>> objUser.SetInfo
>>>
>>> ' Separate section to enable account with its password
>>> objUser.userAccountControl = 512
>>> objUser.pwdLastSet = 0
>>> objUser.SetPassword strPWD
>>> objUser.SetInfo
>>>
>>> intRow = intRow + 1
>>> Loop
>>> msgbox "Script met succes uitgevoerd",8,1
>>> objExcel.Quit
>>>
>>> WScript.Quit
>>>
>>>
>>> ' End of free example UserSpreadsheet VBScript.

>>
>> I don't see anything that would work in W2k3 but not W2k8, with the
>> possible exception of strong passwords. A minor point is that I would
>> remove the space before the comma in the following statement:
>>
>> strOU = "OU=Studenten ," ' Note the comma
>>
>> If the error is raised on the first SetInfo, then the problem is with cn,
>> sAMAccountName, givenName, or sn. The only way givenName or sn will raise
>> an error is if the value is blank. If this is possible, test for it and
>> do not assign if the value in the spreadsheet is blank. cn will raise an
>> error if it is not unique in the container, sAMAccountName will raise an
>> error if it is not unique in the domain.
>>
>> I don't see how an error could be raised on the second SetInfo statement,
>> unless for some reason 512 is not allowed for userAccountControl. It
>> might help to use the AccountDisabled property method instead to enable
>> the account. For example
>>
>> objUser.AccountDisabled = False
>>
>> Finally, if the error is raised on the SetPassword statement, then your
>> password does not meet domain requirements, probably complexity.
>>



 
Reply With Quote
 
Richard Mueller [MVP]
Guest
Posts: n/a

 
      06-12-2009
The maximum length for the cn attribute is 64 characters. I think your error
is most likely due to an embedded comma in the cn, or a similar character
that must be escaped.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--

"Richard Mueller [MVP]" <rlmueller-> wrote in
message news:...
> The sn and givenName attributes can be assigned anything, except a blank
> string. If there is no value for either of these, just don't assign any
> value.
>
> If the value for sAMAccountName is unique in the domain, and the value of
> cn is unique in the OU, then the only possible causes of the error I can
> think of are:
>
> 1. You don't have permission to create user objects in the OU.
> 2. The sAMAccountName is more than 20 characters long.
> 3. The cn is more than 104 characters (if I remember correctly).
> 4. The sAMAccountName includes any of the following characters:
> [ ] : ; | = + ? < > * "
> 5. If the value of the cn attribute includes any of the following
> characters:
> , \ # + < > ; " = /
> or a leading or trailing space, then the character must be escaped using
> the backslash, "\", escape character. For example, if the common name is
> "Smith, Jim", then you must specify "Smith\, Jim". See this link for
> details:
>
> http://www.rlmueller.net/CharactersEscaped.htm
>
> Hopefully this accounts for the error.
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
>
> "nico" <> wrote in message
> news:...
>> R.,
>>
>> the error is raised on the first SetInfo
>>
>> neither givenName or sn is blank and
>> sAMAccountName is unique (the same as sn and givenname)
>>
>> the error has as source "active directory"
>> and the (translated from dutch) error = access error
>>
>>
>> any suggestions?
>>
>>
>>
>> Richard Mueller [MVP] schreef:
>>> "nico" <> wrote in message
>>> news:...
>>>> Hello,
>>>>
>>>> I have a script that auto add's student to my AD for win2003 server.
>>>> for win2008server it does not work
>>>> I get errors
>>>>
>>>> Any suggestions?
>>>>
>>>> N.
>>>>
>>>>
>>>>
>>>> ' Author Guy Thomas http://computerperformance.co.uk/
>>>>
>>>> ' ------------------------------------------------------'
>>>> Option Explicit
>>>> Dim objRootLDAP, objContainer, objUser, objShell
>>>> Dim objExcel, objSpread, intRow
>>>> Dim strUser, strOU, strSheet
>>>> Dim strCN, strSam, strFirst, strLast, strPWD
>>>>
>>>> ' -------------------------------------------------------------'
>>>> ' Important change OU= and strSheet to reflect your domain
>>>> ' -------------------------------------------------------------'
>>>>
>>>> strOU = "OU=Studenten ," ' Note the comma
>>>> strSheet = "D:\IT\users aanmaken\adduser.xls"
>>>>
>>>> ' Bind to Active Directory, Users container.
>>>> Set objRootLDAP = GetObject("LDAP://rootDSE")
>>>> Set objContainer = GetObject("LDAP://" & strOU & _
>>>> objRootLDAP.Get("defaultNamingContext"))
>>>>
>>>> ' Open the Excel spreadsheet
>>>> Set objExcel = CreateObject("Excel.Application")
>>>> Set objSpread = objExcel.Workbooks.Open(strSheet)
>>>> intRow = 3 'Row 1 often contains headings
>>>>
>>>> ' Here is the 'DO...Loop' that cycles through the cells
>>>> ' Note intRow, x must correspond to the column in strSheet
>>>> Do Until objExcel.Cells(intRow,1).Value = ""
>>>> strSam = Trim(objExcel.Cells(intRow, 1).Value)
>>>> strCN = Trim(objExcel.Cells(intRow, 2).Value)
>>>> strFirst = Trim(objExcel.Cells(intRow, 3).Value)
>>>> strLast = Trim(objExcel.Cells(intRow, 4).Value)
>>>> strPWD = Trim(objExcel.Cells(intRow, 5).Value)
>>>>
>>>> ' Build the actual User from data in strSheet.
>>>> Set objUser = objContainer.Create("User", "cn=" & strCN)
>>>> objUser.sAMAccountName = strSam
>>>> objUser.givenName = strFirst
>>>> objUser.sn = strLast
>>>> objUser.SetInfo
>>>>
>>>> ' Separate section to enable account with its password
>>>> objUser.userAccountControl = 512
>>>> objUser.pwdLastSet = 0
>>>> objUser.SetPassword strPWD
>>>> objUser.SetInfo
>>>>
>>>> intRow = intRow + 1
>>>> Loop
>>>> msgbox "Script met succes uitgevoerd",8,1
>>>> objExcel.Quit
>>>>
>>>> WScript.Quit
>>>>
>>>>
>>>> ' End of free example UserSpreadsheet VBScript.
>>>
>>> I don't see anything that would work in W2k3 but not W2k8, with the
>>> possible exception of strong passwords. A minor point is that I would
>>> remove the space before the comma in the following statement:
>>>
>>> strOU = "OU=Studenten ," ' Note the comma
>>>
>>> If the error is raised on the first SetInfo, then the problem is with
>>> cn, sAMAccountName, givenName, or sn. The only way givenName or sn will
>>> raise an error is if the value is blank. If this is possible, test for
>>> it and do not assign if the value in the spreadsheet is blank. cn will
>>> raise an error if it is not unique in the container, sAMAccountName will
>>> raise an error if it is not unique in the domain.
>>>
>>> I don't see how an error could be raised on the second SetInfo
>>> statement, unless for some reason 512 is not allowed for
>>> userAccountControl. It might help to use the AccountDisabled property
>>> method instead to enable the account. For example
>>>
>>> objUser.AccountDisabled = False
>>>
>>> Finally, if the error is raised on the SetPassword statement, then your
>>> password does not meet domain requirements, probably complexity.
>>>

>
>



 
Reply With Quote
 
nico
Guest
Posts: n/a

 
      06-15-2009
Richard Mueller [MVP] schreef:
> The sn and givenName attributes can be assigned anything, except a blank
> string. If there is no value for either of these, just don't assign any
> value.
>
> If the value for sAMAccountName is unique in the domain, and the value of cn
> is unique in the OU, then the only possible causes of the error I can think
> of are:
>
> 1. You don't have permission to create user objects in the OU.
> 2. The sAMAccountName is more than 20 characters long.
> 3. The cn is more than 104 characters (if I remember correctly).
> 4. The sAMAccountName includes any of the following characters:
> [ ] : ; | = + ? < > * "
> 5. If the value of the cn attribute includes any of the following
> characters:
> , \ # + < > ; " = /
> or a leading or trailing space, then the character must be escaped using the
> backslash, "\", escape character. For example, if the common name is "Smith,
> Jim", then you must specify "Smith\, Jim". See this link for details:
>
> http://www.rlmueller.net/CharactersEscaped.htm
>
> Hopefully this accounts for the error.
>



Tx for the very appreciated help
the main problem was as it seems that i could not create users with a
script when i was logged on with a new created adminaccount that
neverthelesss was added to the same groups as the regular admin.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows Server 2008 rebooted after auto installing updates John James Update Services 4 09-04-2009 06:01 PM
how to forbid windows server 2008 to auto restart after an sheduled windows update ? loki Update Services 4 08-30-2009 09:33 AM
how to forbid windows server 2008 to auto restart after an sheduled windows update loki Windows Server 3 08-13-2009 08:56 AM
Auto Map Network Drives under SBS 2008 F3 Windows Small Business Server 3 01-16-2009 12:35 AM
Re: Server 2008 how auto mount shares in workgroup mode Pegasus \(MVP\) Windows Server 0 09-13-2008 10:08 AM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59