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.
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.
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