No announcement yet.

create new user, add to local administrators group for all pc names in text file

  • Filter
  • Time
  • Show
Clear All
new posts

  • create new user, add to local administrators group for all pc names in text file

    Attempting to do this over the network with all xp sp2 clients. All of these pcs are in active directory but my focus is the local user accounts not domain user accounts.

    What I want to do:

    1.create new user
    2.add to local administrators group for all pc names referenced in text file C:\computers

    I would like it to be an on-demand script as opposed to a login script scenario.

    Here's where i'm headed but i can't get it to work. The portion in the middle works for my local pc but when i enclose into the loop referencing the text file is when i get errors.

    In full disclosure, only the portion of code nested in between the long dashes is my code, the outer-portion I found in trying to achieve my goal. My end result would be the merge of both parts.

    Please help. Thanks!

    'Create a FileSystemObject
    Set oFS = CreateObject("Scripting.FileSystemObject")
    'Open a text file of computer names
    'with one computer name per line
    Set oTS = oFS.OpenTextFile("c:\computers.txt")

    'go through the text file
    Do Until oTS.AtEndOfStream
    'get the next computer name
    'store it in variable sComputer
    sComputer = oTS.ReadLine


    'create user
    Option Explicit
    ' On Error Resume Next

    Dim objComputer, objGroup, objUser, objWSHNetwork, strComputerName, strFullName, strPassword, strUserName, strDescription

    Set objWSHNetwork = WScript.CreateObject("WScript.Network")
    strComputerName = objWSHNetwork.ComputerName
    Set objComputer = GetObject("WinNT://" & strComputerName)
    Set objGroup = GetObject("WinNT://" & strComputerName & "/Administrators")

    strUserName = InputBox("Please type the username:", "Enter the username")
    strFullName = InputBox("Please type the fullname:", "Enter the fullname")
    strPassword = InputBox("Please type the password:", "Enter the password")
    strDescription = InputBox("Please type the description:", "Enter the description")

    Set objUser = objComputer.Create("User", strUserName)
    objUser.SetPassword strPassword
    objUser.FullName = strFullName
    objUser.Description = strDescription
    objGroup.Add "WinNT://" & strComputerName & "/" & strUserName

    MsgBox "Completed adding user " & strUserName & ".", vbInformation, "Execution completed"

    'close the text file
    MsgBox "Done!"