Created a user called "Admin" on all machines whose names are in a file and add the user to the Local Administrator group with the predefined password.Have a Success & Failure report for the same.

Hi,

Created a user called "Admin" on all machines whose names are in a file and add the user to the Local Administrator group with the predefined password.Have a Success & Failure report for the same.


Regards
Sharath
LVL 11
bsharathAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

 
yehudahaCommented:
added and ping function

change password here:
objUser.SetPassword "test"

list and log file path here:
Set Strlist = objfso.OpenTextFile("c:\list.txt", ForReading)
Set strlog = objfso.CreateTextFile("c:\log,txt", ForWriting)
Set objfso = CreateObject("Scripting.FileSystemObject")
Set Strlist = objfso.OpenTextFile("c:\list.txt", ForReading)
Set strlog = objfso.CreateTextFile("c:\log,txt", ForWriting)
 
Do Until strlist.AtEndOfStream
	strComputer = strlist.ReadLine
	If Reachable(strcomputer) Then
	On Error Resume Next
	Set colAccounts = GetObject("WinNT://" & strComputer & "")
	If err.number <> 0 Then
		strlog.WriteLine "error connecting to " & strComputer & vbcrlf
	Else
		On Error goto 0
	End If
		Set objUser = colAccounts.Create("user", "Admin")
		objUser.SetPassword "test"
		objUser.SetInfo
		Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators")
		objGroup.Add(objUser.ADsPath)
		strlog.WriteLine "user created And Added To Admin Group on " & strcomputer & vbcrlf
	Else
		strlog.WriteLine strcomputer & " Isnt Reachable " & vbcrlf
	End If
Loop
 
Function Reachable(strComputer)
		 
	strCmd = "ping -n 1 " & strComputer
		 
	Set objShell = CreateObject("WScript.Shell")
	Set objExec = objShell.Exec(strCmd)
	strTemp = UCase(objExec.StdOut.ReadAll)
		 
	If InStr(strTemp, "REPLY FROM") Then
		Reachable = True 
	Else
		Reachable = False
	End If
End Function

Open in new window

0
 
bsharathAuthor Commented:
I get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Create Users local.vbs
Line:      2
Char:      1
Error:      Invalid procedure call or argument
Code:      800A0005
Source:       Microsoft VBScript runtime error

---------------------------
OK  
---------------------------
0
 
bsharathAuthor Commented:
I get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Create Users local.vbs
Line:      2
Char:      1
Error:      Invalid procedure call or argument
Code:      800A0005
Source:       Microsoft VBScript runtime error

---------------------------
OK  
---------------------------
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
yehudahaCommented:
opps cut two lines
Const ForReading = 1
Const ForWriting = 2
 
Set objfso = CreateObject("Scripting.FileSystemObject")
Set Strlist = objfso.OpenTextFile("c:\list.txt", ForReading)
Set strlog = objfso.CreateTextFile("c:\log,txt", ForWriting)
 
Do Until strlist.AtEndOfStream
	strComputer = strlist.ReadLine
	If Reachable(strcomputer) Then
	On Error Resume Next
	Set colAccounts = GetObject("WinNT://" & strComputer & "")
	If err.number <> 0 Then
		strlog.WriteLine "error connecting to " & strComputer & vbcrlf
	Else
		On Error goto 0
	End If
		Set objUser = colAccounts.Create("user", "Admin")
		objUser.SetPassword "test"
		objUser.SetInfo
		Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators")
		objGroup.Add(objUser.ADsPath)
		strlog.WriteLine "user created And Added To Admin Group on " & strcomputer & vbcrlf
	Else
		strlog.WriteLine strcomputer & " Isnt Reachable " & vbcrlf
	End If
Loop
 
Function Reachable(strComputer)
		 
	strCmd = "ping -n 1 " & strComputer
		 
	Set objShell = CreateObject("WScript.Shell")
	Set objExec = objShell.Exec(strCmd)
	strTemp = UCase(objExec.StdOut.ReadAll)
		 
	If InStr(strTemp, "REPLY FROM") Then
		Reachable = True 
	Else
		Reachable = False
	End If
End Function

Open in new window

0
 
bsharathAuthor Commented:
Works fine...
Can i have the "Password never expires checked"
&
Have a description for the User that is created
0
 
bsharathAuthor Commented:
Works fine...
Can i have the "Password never expires checked"
&
Have a description for the User that is created
0
 
yehudahaCommented:
ok i think this will do it:

description here:
strDesc = "very important admin account"
Const ForReading = 1
Const ForWriting = 2
Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000
 
strDesc = "very important admin account"
 
Set objfso = CreateObject("Scripting.FileSystemObject")
Set Strlist = objfso.OpenTextFile("c:\list.txt", ForReading)
Set strlog = objfso.CreateTextFile("c:\log,txt", ForWriting)
 
Do Until strlist.AtEndOfStream
	strComputer = strlist.ReadLine
	If Reachable(strcomputer) Then
		On Error Resume Next
		Set colAccounts = GetObject("WinNT://" & strComputer & "")
		If err.number <> 0 Then
			strlog.WriteLine "error connecting to " & strComputer & vbcrlf
		Else
			On Error goto 0
		End If
		Set objUser = colAccounts.Create("user", "Admin")
		objUser.SetPassword "test"
		objUser.Description = strDescr
		objUserFlags = objUser.Get("UserFlags")
		objPasswordExpirationFlag = objUserFlags Or ADS_UF_DONT_EXPIRE_PASSWD
		objUser.Put "userFlags", objPasswordExpirationFlag 
		objUser.SetInfo
		Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators")
		objGroup.Add(objUser.ADsPath)
		strlog.WriteLine "user created And Added To Admin Group on " & strcomputer & vbcrlf
	Else
		strlog.WriteLine strcomputer & " Isnt Reachable " & vbcrlf
	End If
Loop
 
Function Reachable(strComputer)
	                 
	strCmd = "ping -n 1 " & strComputer
	                 
	Set objShell = CreateObject("WScript.Shell")
	Set objExec = objShell.Exec(strCmd)
	strTemp = UCase(objExec.StdOut.ReadAll)
	                 
	If InStr(strTemp, "REPLY FROM") Then
		Reachable = True 
	Else
		Reachable = False
	End If
End Function

Open in new window

0
 
yehudahaCommented:
change this

objUser.Description = strDescr

to this:

objUser.Description = strDesc
0
 
bsharathAuthor Commented:
I get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Create Users local.vbs
Line:      24
Char:      3
Error:      The specified directory object is not bound to a remote resource

Code:      80005009
Source:       Active Directory

---------------------------
OK  
---------------------------

Does this code handle permissions issue too
0
 
bsharathAuthor Commented:
I get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Create Users local.vbs
Line:      24
Char:      3
Error:      The specified directory object is not bound to a remote resource

Code:      80005009
Source:       Active Directory

---------------------------
OK  
---------------------------

Does this code handle permissions issue too
0
 
yehudahaCommented:
try this:
Const ForReading = 1
Const ForWriting = 2
Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000
 
strDesc = "very important admin account"
 
Set objfso = CreateObject("Scripting.FileSystemObject")
Set Strlist = objfso.OpenTextFile("c:\list.txt", ForReading)
Set strlog = objfso.CreateTextFile("c:\log,txt", ForWriting)
 
Do Until strlist.AtEndOfStream
        strComputer = strlist.ReadLine
        If Reachable(strcomputer) Then
                On Error Resume Next
                Set colAccounts = GetObject("WinNT://" & strComputer & "")
                If err.number <> 0 Then
                        strlog.WriteLine "error connecting to " & strComputer & vbcrlf
                Else
                        On Error goto 0
                End If
                Set objUser = colAccounts.Create("user", "Admin")
                objUser.SetPassword "test"
                objUser.Description = strDesc 
                objUser.SetInfo
                objUserFlags = objUser.Get("UserFlags")
                objPasswordExpirationFlag = objUserFlags OR ADS_UF_DONT_EXPIRE_PASSWD
                objUser.Put "userFlags", objPasswordExpirationFlag 
                objUser.SetInfo
                Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators")
                objGroup.Add(objUser.ADsPath)
                strlog.WriteLine "user created And Added To Admin Group on " & strcomputer & vbcrlf
        Else
                strlog.WriteLine strcomputer & " Isnt Reachable " & vbcrlf
        End If
Loop
 
Function Reachable(strComputer)
                         
        strCmd = "ping -n 1 " & strComputer
                         
        Set objShell = CreateObject("WScript.Shell")
        Set objExec = objShell.Exec(strCmd)
        strTemp = UCase(objExec.StdOut.ReadAll)
                         
        If InStr(strTemp, "REPLY FROM") Then
                Reachable = True 
        Else
                Reachable = False
        End If
End Function

Open in new window

0
 
bsharathAuthor Commented:
Thanks works but get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Create Users local.vbs
Line:      24
Char:      17
Error:      The account already exists.
Code:      800708B0
Source:       (null)

---------------------------
OK  
---------------------------

Can i get this recorded in the log rather than stopping the existing list of machines
0
 
bsharathAuthor Commented:
Thanks works but get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Create Users local.vbs
Line:      24
Char:      17
Error:      The account already exists.
Code:      800708B0
Source:       (null)

---------------------------
OK  
---------------------------

Can i get this recorded in the log rather than stopping the existing list of machines
0
 
yehudahaCommented:
try this:
Const ForReading = 1
Const ForWriting = 2
Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000
 
strDesc = "very important admin account"
 
Set objfso = CreateObject("Scripting.FileSystemObject")
Set Strlist = objfso.OpenTextFile("c:\list.txt", ForReading)
Set strlog = objfso.CreateTextFile("c:\log.txt", ForWriting)
 
Do Until strlist.AtEndOfStream
        strComputer = strlist.ReadLine
        If Reachable(strcomputer) Then
                On Error Resume Next
                Set colAccounts = GetObject("WinNT://" & strComputer & "")
                If err.number <> 0 Then
                        strlog.WriteLine "error connecting to " & strComputer & vbcrlf
                Else
                        On Error goto 0
                End If
                Set objUser = colAccounts.Create("user", "Admin")
                objUser.SetPassword "test"
                objUser.Description = strDesc 
                On Error Resume next
                objUser.SetInfo
                If Err.Number <> 0 Then
                strlog.WriteLine "Probably User Exist on " & strComputer
                Else
                On Error GoTo 0
                End If
                objUserFlags = objUser.Get("UserFlags")
                objPasswordExpirationFlag = objUserFlags OR ADS_UF_DONT_EXPIRE_PASSWD
                objUser.Put "userFlags", objPasswordExpirationFlag 
                objUser.SetInfo
                Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators")
                objGroup.Add(objUser.ADsPath)
                If Err.Number <> 0 Then
                strerr = True
                else
                strlog.WriteLine "user created And Added To Admin Group on " & strcomputer & VbCrLf
                End if
        Else
                strlog.WriteLine strcomputer & " Isnt Reachable " & vbcrlf
        End If
Loop
 
Function Reachable(strComputer)
                         
        strCmd = "ping -n 1 " & strComputer
                         
        Set objShell = CreateObject("WScript.Shell")
        Set objExec = objShell.Exec(strCmd)
        strTemp = UCase(objExec.StdOut.ReadAll)
                         
        If InStr(strTemp, "REPLY FROM") Then
                Reachable = True 
        Else
                Reachable = False
        End If
End Function

Open in new window

0

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
 
bsharathAuthor Commented:
Thank a lot worked perfect
0
 
bsharathAuthor Commented:
After a long run i get this error...

---------------------------
Windows Script Host
---------------------------
Script:      C:\Create Users local.vbs
Line:      35
Char:      17
Error:      The group name could not be found.
Code:      800708AC
Source:       (null)

---------------------------
OK  
---------------------------
0
 
yehudahaCommented:
do you have computers with non english os ?
0
 
bsharathAuthor Commented:
Yes i do have....
0
 
yehudahaCommented:
how many ? wich languages ?

basicly because on this computers adminstrators group named in the os language, so the script
doesnt find the group.
0
 
bsharathAuthor Commented:
Ok can we skip in such cases. As i may have just a very few. Those i can do them manually.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.