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

Viewing 1 post (of 1 total)
  • Author

  • keensab

    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!”

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

External Sharing and Guest User Access in Microsoft 365 and Teams

This eBook will dive into policy considerations you need to make when creating and managing guest user access to your Teams network, as well as the different layers of guest access and the common challenges that accompany a more complicated Microsoft 365 infrastructure.

You will learn:

  • Who should be allowed to be invited as a guest?
  • What type of guests should be able to access files in SharePoint and OneDrive?
  • How should guests be offboarded?
  • How should you determine who has access to sensitive information in your environment?

Sponsored by: