Jump to content


  • 0
petebuk

Script to Add local admin account

Question

Hello there: I have the below scritpt to add a local admin account to a list of computers in a txt file however it will only add thr account to the first computer name in the text file. I have one computer name per line in the text file itself.

 

Any Ideas?

 

' --------------------------------------------------------

' VARIABLE DECLARATIONS

' --------------------------------------------------------

Option Explicit

Dim strFile

Dim objFSO, objTS, strComputer, objNetwork, objComputer, colAccounts, objUser, objGroup

 

 

' --------------------------------------------------------

' STATIC VARIABLE ASSIGNMENTS

' --------------------------------------------------------

strFile = "\\warcorpfp2\Public\Helpdesk\WheelsComputers.txt"

 

 

' --------------------------------------------------------

' MAIN SCRIPT CODE

' --------------------------------------------------------

Set objFSO = CreateObject("Scripting.FileSystemObject")

 

If objFSO.FileExists(strFile) Then

' Open File

Set objTS = objFSO.OpenTextFile(strFile)

 

'Loop through each line in the file

Do Until objTS.AtEndOfStream

'Get contents of line

strComputer = objTS.ReadLine

 

 

' --------------------------------------------------------

' CREATE CEWADMIN ON COMPUTER

' --------------------------------------------------------

 

'Get Network Object

Set objNetwork = CreateObject("Wscript.Network")

'Get Computer Object

Set objComputer = GetObject("WinNT://" & strComputer)

'Get a list of accounts on computer

Set colAccounts = GetObject("WinNT://" & strComputer & "")

'Create cewadmin user

Set objUser = colAccounts.Create("user", "cewadmin")

objUser.SetPassword "xxxx"

objUser.Put "UserFlags", 65600

'Save/Update user

objUser.SetInfo

 

'add to administrators group

'Get admin group

Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")

'Get cewadmin user

Set objUser = GetObject("WinNT://" & strComputer & "/cewadmin,user")

'Add cewadmin user to admin group

objGroup.Add(objUser.ADsPath)

 

Loop

End If

 

objTS.Close

WScript.Echo "Complete"

Share this post


Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.