[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 833
  • Last Modified:

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
0
bsharath
Asked:
bsharath
  • 12
  • 8
1 Solution
 
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 12
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now