Script for adding users

I'm trying to run this script on a local desktop for testing. I plan to use the script in a group policy.
When I run the script on my local computer nothing happens. Ive tried googling the problem and got several answers but im still confused, which isnt hard. any help would be great.



Set objNetwork = WScript.CreateObject("WScript.Network")
Set objGroup = GetObject("WinNT://" & objNetwork.ComputerName & "/Users,group")
strArgument = "contoso\lintern"


For Each strArgument in Wscript.Arguments
     x = InStr(strArgument,"\")
     if X>0 Then
          Domain_Name = Left(strArgument,x-1)
          Admin_Name = Right(strArgument,Len(strArgument)-x)
          DNPath = "WinNT://" & Domain_Name & "/" & Admin_Name

          On Error Resume Next
          If Not objGroup.IsMember(DNPath) Then objGroup.Add(DNPath)
          ON Error Goto 0

          End If
     Next

Set objGroup = Nothing
set objNetwork = Nothing
RoodonaAsked:
Who is Participating?
 
RobSampsonConnect With a Mentor Commented:
The script you have is not creating any user, it is only adding the domain user to the local administrator group.

So, are you saying that you plan to create <localmachine>\lintern on EVERY computer, then remove the domain account?

This code will connect to the local Admin group and create a user called Lintern.

Rob.
strUser = "Lintern"
strPassword = "password"
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set colAccounts = GetObject("WinNT://" & strComputer & "")
Set objUser = colAccounts.Create("user", strUser)
objUser.SetPassword strPassword
objUser.SetInfo
Set objLocalUser = GetObject("WinNT://" & strComputer & "/" & strUser)
Set objLocalAdmGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")
objLocalAdmGroup.Add(objLocalUser.AdsPath)

Open in new window

0
 
Jan Vojtech VanicekIT SpecialistCommented:
How do you want to use it in group policy? What it should do?
0
 
RobSampsonCommented:
Hi, the script is designed to be run with
myscript.vbs <argument>

and not use
strArgument = "contoso\lintern"

but if you want to hard code the argument, use this instead.

Regards,

Rob.
Set objNetwork = WScript.CreateObject("WScript.Network")
Set objGroup = GetObject("WinNT://" & objNetwork.ComputerName & "/Users,group")
arrArguments = Array("contoso\lintern")


For Each strArgument in arrArguments
     x = InStr(strArgument,"\")
     if X>0 Then
          Domain_Name = Left(strArgument,x-1)
          Admin_Name = Right(strArgument,Len(strArgument)-x)
          DNPath = "WinNT://" & Domain_Name & "/" & Admin_Name

          On Error Resume Next
          If Not objGroup.IsMember(DNPath) Then objGroup.Add(DNPath)
          ON Error Goto 0

          End If 
     Next

Set objGroup = Nothing
set objNetwork = Nothing

Open in new window

0
Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

 
RoodonaAuthor Commented:
My goals are when the script runs on a domain computer it creates and account/password and dumps it in the Local admin group. The script posted above doesn't work. Sorry to be a pain
0
 
RoodonaAuthor Commented:
The lintern is a domain account that cant be domain admin just a regular user
0
 
RobSampsonCommented:
Thanks for the grade.

Regards,

Rob.
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.