Dear All

(Also posted this in VBScript as i dont know which applies more !!)

Below is a full copy of my code to date which seems to work nicely.
Im still tinkering with it as parts are yet to be added home dir etc.

Basically it pulls users from a CSV and creates their accounts.

However how on earth do i add them to a group....????

Every user will by default need to be a member of the "students" Group so
can this be hardcoded somehow..?
Then they need to be a member of a more specific group pertaining to that
class only.

Ideas anyone..?

Cheers
Paul

---------------------------------------------------------------------------------------------

Option Explicit

Dim sCSVFileLocation
Dim sCSVFile
Dim oConnection
Dim oRecordSet
Dim oNewUser

' Variables needed for LDAP connection
Dim oRootLDAP
Dim oContainer

' Holding variables for information import from CSV file
Dim sLogon
Dim sFirstName
Dim sLastName
Dim sDisplayName
Dim sdescription
Dim sNAME
Dim sPassword
Dim nPwdLastSet
Dim nUserAccountControl ' Used to enable the account
Dim sDomain

' Modify this to match your company's AD domain
sDomain="mydomain.co.uk"

' Input file location
sCSVFileLocation = "C:\Scripts\" 'KEEP TRAILING SLASH!

' Full path to input file
sCSVFile = sCSVFileLocation&"User.csv"

' Commands used to open the CSV file and select all of the records
set oConnection = createobject("adodb.connection")
set oRecordSet = createobject("adodb.recordset")
oConnection.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " &
sCSVFileLocation & ";Extended Properties=""text;HDR=yes;FMT=Delimited"""
oRecordSet.open "SELECT * FROM " & sCSVFile ,oConnection

' Create a connection to the Active Directory Users container.
Set oRootLDAP = GetObject("LDAP://rootDSE")
Set oContainer = GetObject("LDAP://ou=StudentsGP," & _
oRootLDAP.Get("defaultNamingContext"))

' Allows processing to continue even if an error occurs (i.e. dup user)
' We put this below the CSV and AD information since processing can
' continue with a single bad record, but not if there is a problem with
' the CSV file or AD connection
on error resume next

do until oRecordSet.EOF ' Reads the values (cells) in the sInputFile file.



' --------- Start creating user account
' Read variable information from the CSV file
' and build everything needed to create the account

sFirstName = oRecordSet.Fields.Item(1).value
sLastName = oRecordSet.Fields.Item(2).value
sLogon = sFirstName&"."&sLastName
sDisplayName = sFirstName&" "&sLastName
sPassword = oRecordSet.Fields.Item(3).value
sdescription = oRecordSet.Fields.Item(4).value
sNAME = oRecordSet.Fields.Item(5).value

' Build the User account
Set oNewUser = oContainer.Create("User","cn="&sFirstName&" "&SLastName)

oNewUser.put "sAMAccountName",lcase(sLogon)
oNewUser.put "givenName",sFirstName
oNewUser.put "sn",sLastName
oNewUser.put "UserPrincipalName",lcase(SLogon)&"@"&sDomain
oNewUser.put "DisplayName",sDisplayName
oNewUser.put "description",sdescription
oNewUser.put "name",lcase(sLogon)
oNewUser.put "scriptPath",sNAME

' Write this information into Active Directory so we can
' modify the password and enable the user account
oNewUser.SetInfo

' Change the users password
oNewUser.SetPassword sPassword
oNewUser.Put "pwdLastSet", 0

' Enable the user account
oNewUser.Put "userAccountControl", 512
oNewUser.Put "userAccountControl", 66048
oNewUser.SetInfo

' Used only for debugging
if err.number = -2147019886 then
msgbox "User logon " & sLogon & "already exists"
end if


oRecordSet.MoveNext

loop

-----------------------------------------------------------------------------------

Re: User Creation with VBS how to add to Group by Jorge

Jorge
Tue Jun 17 02:35:36 PDT 2008

Hi
Have a look at:
http://www.microsoft.com/technet/scriptcenter/scripts/ad/default.mspx?mfr=true

--
I hope that the information above helps you.
Have a Nice day.

Jorge Silva
MCSE, MVP Directory Services


Re: User Creation with VBS how to add to Group by PK

PK
Tue Jun 17 05:43:01 PDT 2008

Hi there

bolted this in..

Set objOU = GetObject("LDAP://OU=Management,dc=fabrikam,dc=com")
Set objGroup = objOU.Create("Group", "cn=atl-users")
objGroup.Put "sAMAccountName", "atl-users"
objGroup.SetInfo

But still no joy..donst create the group or add them to it.

Cheers
Paul

"Jorge Silva" wrote:

> Hi
> Have a look at:
> http://www.microsoft.com/technet/scriptcenter/scripts/ad/default.mspx?mfr=true
>
> --
> I hope that the information above helps you.
> Have a Nice day.
>
> Jorge Silva
> MCSE, MVP Directory Services
>
>

Re: User Creation with VBS how to add to Group by Paul

Paul
Tue Jun 17 06:10:07 PDT 2008

Do you really have an OU named management in the fabrikam.com domain? I'm
guessing you don't. Then it appears you are trying to add the group to
itself.

You should start this thread over in the scripting NewsGroup

NG = microsoft.public.scripting.vbscrip


--
Paul Bergson
MVP - Directory Services
MCTS, MCT, MCSE, MCSA, Security+, BS CSci
2008, 2003, 2000 (Early Achiever), NT4

http://www.pbbergs.com

Please no e-mails, any questions should be posted in the NewsGroup
This posting is provided "AS IS" with no warranties, and confers no rights.

"PK" <PK@discussions.microsoft.com> wrote in message
news:74572FE1-3519-41D3-911F-4E28D386ED9C@microsoft.com...
> Hi there
>
> bolted this in..
>
> Set objOU = GetObject("LDAP://OU=Management,dc=fabrikam,dc=com")
> Set objGroup = objOU.Create("Group", "cn=atl-users")
> objGroup.Put "sAMAccountName", "atl-users"
> objGroup.SetInfo
>
> But still no joy..donst create the group or add them to it.
>
> Cheers
> Paul
>
> "Jorge Silva" wrote:
>
>> Hi
>> Have a look at:
>> http://www.microsoft.com/technet/scriptcenter/scripts/ad/default.mspx?mfr=true
>>
>> --
>> I hope that the information above helps you.
>> Have a Nice day.
>>
>> Jorge Silva
>> MCSE, MVP Directory Services
>>
>>



Re: User Creation with VBS how to add to Group by PK

PK
Tue Jun 17 06:24:00 PDT 2008

Sorry that was a cut and passte from MS site,
Just one of the many permutations i have tried.

I of course had modified it accordingly when in test

Kr
Paul

"Paul Bergson [MVP-DS]" wrote:

> Do you really have an OU named management in the fabrikam.com domain? I'm
> guessing you don't. Then it appears you are trying to add the group to
> itself.
>
> You should start this thread over in the scripting NewsGroup
>
> NG = microsoft.public.scripting.vbscrip
>
>
> --
> Paul Bergson
> MVP - Directory Services
> MCTS, MCT, MCSE, MCSA, Security+, BS CSci
> 2008, 2003, 2000 (Early Achiever), NT4
>
> http://www.pbbergs.com
>
> Please no e-mails, any questions should be posted in the NewsGroup
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
> "PK" <PK@discussions.microsoft.com> wrote in message
> news:74572FE1-3519-41D3-911F-4E28D386ED9C@microsoft.com...
> > Hi there
> >
> > bolted this in..
> >
> > Set objOU = GetObject("LDAP://OU=Management,dc=fabrikam,dc=com")
> > Set objGroup = objOU.Create("Group", "cn=atl-users")
> > objGroup.Put "sAMAccountName", "atl-users"
> > objGroup.SetInfo
> >
> > But still no joy..donst create the group or add them to it.
> >
> > Cheers
> > Paul
> >
> > "Jorge Silva" wrote:
> >
> >> Hi
> >> Have a look at:
> >> http://www.microsoft.com/technet/scriptcenter/scripts/ad/default.mspx?mfr=true
> >>
> >> --
> >> I hope that the information above helps you.
> >> Have a Nice day.
> >>
> >> Jorge Silva
> >> MCSE, MVP Directory Services
> >>
> >>
>
>
>

Re: User Creation with VBS how to add to Group by Jorge

Jorge
Tue Jun 17 07:37:38 PDT 2008

-Did you read the link?
-To create the Goup and add 1000 users:
--------------------------------------------------------
Const ADS_PROPERTY_APPEND = 3

Set objRootDSE = GetObject("LDAP://rootDSE")
Set objContainer = GetObject("LDAP://cn=Users," & _
objRootDSE.Get("defaultNamingContext"))
Set objGroup = objContainer.Create("Group", "cn=Group1")
objGroup.Put "sAMAccountName","Group1"
objGroup.SetInfo

For i = 1 To 1000
strDN = ",cn=Users," & objRootDSE.defaultNamingContext
objGroup.PutEx ADS_PROPERTY_APPEND, "member", _
Array("cn=UserNo" & i & strDN)
objGroup.SetInfo
Next
WScript.Echo "Group1 created and 1000 Users added to the group."
--------------------------------------------------------

--
I hope that the information above helps you.
Have a Nice day.

Jorge Silva
MCSE, MVP Directory Services