[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Script for adding users

Posted on 2010-01-04
6
Medium Priority
?
271 Views
Last Modified: 2012-05-08
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
0
Comment
Question by:Roodona
  • 3
  • 2
6 Comments
 
LVL 6

Expert Comment

by:Jan Vojtech Vanicek
ID: 26175487
How do you want to use it in group policy? What it should do?
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 26176068
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
 

Author Comment

by:Roodona
ID: 26180531
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Roodona
ID: 26180539
The lintern is a domain account that cant be domain admin just a regular user
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 2000 total points
ID: 26185369
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
 
LVL 65

Expert Comment

by:RobSampson
ID: 26205104
Thanks for the grade.

Regards,

Rob.
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Why do some people recommend buying business VoIP from an ISP? What are the benefits to my company? What are the costs?
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question