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

Home Forums Scripting Windows Script Host create new user, add to local administrators group for all pc names in text file

This topic contains 0 replies, has 1 voice, and was last updated by Avatar keensab 8 years, 10 months ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • Avatar
    keensab
    Member
    #151417

    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
    objUser.SetInfo
    objGroup.Add “WinNT://” & strComputerName & “/” & strUserName
    objUser.SetInfo

    MsgBox “Completed adding user ” & strUserName & “.”, vbInformation, “Execution completed”


    Loop
    ‘close the text file
    oTS.Close
    MsgBox “Done!”

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

Register for this Petri Webinar!

Want to Make Your Backup Storage Unlimited & Ready for the Cloud? – Free Thurrott Premium Account with Webinar Registration!

Tuesday, August 27, 2019 @ 1:00 pm EDT

A Scale-Out Backup storage infrastructure is a must-have technology for your backups. In this webinar, join expert Rick Vanover for a look on what real-world problems are solved by the Scale-Out Backup Repository.

Register Now

Sponsored By