!!!! Need a Vbscript to create local groups & local users' account via txt file.

Hi Expert

I need to create 20 local groups & 60 local users accounts in windows 2003 Server R2 64-bits. I know set groups and users in the local server this is silly way, but we have special reason to do this way.

is it possible to use a VbScript to create groups, and users via reading TXT file? it would be great if the vbscript can assign user into group as well. I am a quite new in the vbscript. I know some vbscript such as create a user account into AD, please see the code section. But i dont know how to modify to meet my current requirements.

I appreicate for your help.

Cheers

Set objDomain = GetObject("LDAP://dc=fabrikam,dc=com")
Set objOU = objDomain.Create("organizationalUnit", "ou=Management")
objOU.SetInfo
 
Set objOU = GetObject("LDAP://OU=Management,dc=fabrikam,dc=com")
Set objUser = objOU.Create("User", "cn= AckermanPilar")
objUser.Put "sAMAccountName", "AckermanPila"
objUser.SetInfo
 
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
 
objGroup.Add objUser.ADSPath

Open in new window

mxgongAsked:
Who is Participating?
 
karstiemanConnect With a Mentor Commented:
Oh, create groups can be done by

just make a textfile and list the new groups to be created

finance_users
humanresource_users
it_users
etc.
etc.
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
    ("c:\YOURTEXTFILE.TXT", ForReading)
Do Until objTextFile.AtEndOfStream
 
    strNEWGROUP = objTextFile.Readline
    strComputer = "MyComputer"
    Set colAccounts = GetObject("WinNT://" & strComputer & "")
    Set objUser = colAccounts.Create("group", strNEWGROUP )
    objUser.SetInfo
 
Loop

Open in new window

0
 
karstiemanCommented:
Here's the code.

Good luck

Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
    ("c:\YOURTEXTFILE.TXT", ForReading)
Do Until objTextFile.AtEndOfStream
 
    strOU= objTextFile.Readline
    Set objDomain = GetObject("LDAP://dc=fabrikam,dc=com")
    Set objOU = objDomain.Create("organizationalUnit", "ou=" & strOU)
    objOU.SetInfo
 
    strUSER = objTextFile.Readline
    Set objOU = GetObject("LDAP://OU=" & strOU & ",dc=fabrikam,dc=com")
    Set objUser = objOU.Create("User", "cn="& strUSER )
    objUser.Put "sAMAccountName", strUSER 
    objUser.SetInfo
 
    strGROUPNAME= objTextFile.Readline
    Set objOU = GetObject("LDAP://OU=" & strOU & ",dc=fabrikam,dc=com")
    Set objGroup = objOU.Create("Group", "cn=" & strGROUPNAME)
    objGroup.Put "sAMAccountName", strGROUPNAME
    objGroup.SetInfo
 
    objGroup.Add objUser.ADSPath
Loop

Open in new window

0
 
karstiemanCommented:
Oh, forgot how your textfile should look like: ( no spaces / enters before the first line and after the last line! )
----------------------
OUNAME
USERNAME
GROUPNAME
OUNAME
USERNAME
GROUPNAME
OUNAME
USERNAME
GROUPNAME
----------------------
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
mxgongAuthor Commented:
Hi, karstieman:

thanks for your quick reply.

I need a VB script to create local groups and  local users in the Windows 2003 R2 64-bit (not DC), not in the AD. Could you please help me to modify your code?

THanks for your time and help
0
 
karstiemanCommented:
OK, here it is

Make sure the groupname exists on the pc.
for example administrators is a correct local group.

textfile should look like this

USERNAME
PASSWORD
GROUPNAME
USERNAME
PASSWORD
GROUPNAME
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
    ("c:\YOURTEXTFILE.TXT", ForReading)
Do Until objTextFile.AtEndOfStream
 
    strUSER = objTextFile.Readline
    Set location = GetObject("WinNT://server,computer")
    set objuser = location.create("user", strUSER)
   
    strPASSWORD =  objTextFile.Readline
    objuser.setpassword strPASSWORD
    objUser.SetInfo
 
    strGROUPNAME= objTextFile.Readline
    Set Group = GetObject("WinNT://server/" & strGROUPNAME & ",group")
    Group.Add(objuser.ADspath)
Loop

Open in new window

0
 
mxgongAuthor Commented:
Hi karstieman:

I will test your code tommorrow, and get feedback to you by tommorrow.

Thanks

Have a nice weekend.
0
 
mxgongAuthor Commented:
Hi Karstieman:

When I run your second code (please see following coding), i got the error message:

(13,5) Active Directory: Unspecified error

Please help!  Thanks
' Create group(s) via TXT file in Local Machine
 
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
    ("C:\group.txt", ForReading)
Do Until objTextFile.AtEndOfStream
 
    strNEWGROUP = objTextFile.Readline
    strComputer = "MyComputer"
    Set colAccounts = GetObject("WinNT://" & strComputer & "")
    Set objUser = colAccounts.Create("group", strNEWGROUP )
    objUser.SetInfo
 
Loop

Open in new window

0
 
mxgongAuthor Commented:
Thanks I have fixed this problem.


I am doting more testing now.

I will get you feedback by tommorrow.

Cheers
0
 
mxgongAuthor Commented:
Thanks
0
 
MrVaultCommented:
did this get fixed? I'm interested in this solution.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.