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

x
?
Solved

Add Domain administrator in each machine in the txt files group call Sophos Administrator.

Posted on 2009-02-19
31
Medium Priority
?
450 Views
Last Modified: 2012-05-06
Hi,

Add Domain administrator in each machine in the txt files group call Sophos Administrator.
Need a success & failure report
Has to skip permission issues and ping failures and WMI errors

Regards
Sharath
0
Comment
Question by:bsharath
  • 19
  • 12
31 Comments
 
LVL 14

Expert Comment

by:yehudaha
ID: 23686176
hey change this lines :
Set objlist = objfso.OpenTextFile("c:\list.txt", ForReading) -- >> list of machines
Set objlog = objfso.CreateTextFile("c:\log.txt", ForWriting) --- >> log file

put your domain name and the group name here
domain only the name without com or net:

strGroupName = "WinNT://fabrikam/accounting" --- >>  "WinNT://domain/Sophos Administrator"
Const ForReading = 1
Const ForWriting = 2
  
Set objfso = CreateObject("Scripting.FileSystemObject")
Set objlist = objfso.OpenTextFile("c:\list.txt", ForReading)
Set objlog = objfso.CreateTextFile("c:\log.txt", ForWriting)
 
strGroupName = "WinNT://fabrikam/accounting"
 
Do Until objlist.AtEndOfStream
strComputer = objlist.ReadLine
If Reachable(strComputer) Then
   If per(strcomputer) then
Set objAdmins = GetObject("WinNT://" & strComputer & "/Administrators")
Set objGroup = GetObject(strGroupName)
On Error Resume Next
objAdmins.Add(objGroup.ADsPath)
If Err.Number = 0 Then
    Err.Clear
    objlog.WriteLine "group created on " & strcomputer & vbCrLf
    On Error Goto 0
    Else
    Err.Clear
    objlog.WriteLine "error creatring the group on " & strcomputer & vbCrLf
    On Error Goto 0
End if
Else
objlog.WriteLine "you don't have permission on " & strcompuer & vbcrlf
End If
Else
objlog.WriteLine strcomputer & " is not 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
 
Function per(computer)
	strcomputer = computer
	On Error Resume Next
	Set objWMIService = GetObject("winmgmts:" _
	& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
	If err.number <> 0 Then
		err.Clear
		per = False
		On Error goto 0
	Else
		per = True
		On Error goto 0
	End If
End Function

Open in new window

0
 
LVL 14

Expert Comment

by:yehudaha
ID: 23686337
don't use it
0
 
LVL 14

Expert Comment

by:yehudaha
ID: 23686349
Sophos Administrator local or domain and to add only one user to it domain admin ?

be more clear please
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 11

Author Comment

by:bsharath
ID: 23688413
Thank U
Need to add Domain\Administrator to each machines local group called Sophos Administrator.

Add User Domain\Administrator to the group
0
 
LVL 11

Author Comment

by:bsharath
ID: 23688966
The below code works but get errors when off or when permissions has an issue. Or when the user already exists in the group...
strOutputFile = "C:\Workstations.txt"
strUser = "Administrator"
 
Const OPEN_FILE_FOR_READING = 1
Const OPEN_FILE_FOR_APPENDING = 8
 
' Set Objects
 
Set oFSO = CreateObject("Scripting.fileSystemObject")
Set objInputFile = oFSO.OpenTextFile(strOutputFile, _
  OPEN_FILE_FOR_READING)
 
inputData = Split(objInputFile.ReadAll, vbNewline)
 
For each strData In inputData
 
strComputer = strData
 
Set objGroup = GetObject("WinNT://" & strComputer & "/SophosAdministrator")
Set objUser = GetObject("WinNT://Development/" & strUser)
objGroup.Add(objUser.ADsPath)
 
Next

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 23688967
The below code works but get errors when off or when permissions has an issue. Or when the user already exists in the group...
strOutputFile = "C:\Workstations.txt"
strUser = "Administrator"
 
Const OPEN_FILE_FOR_READING = 1
Const OPEN_FILE_FOR_APPENDING = 8
 
' Set Objects
 
Set oFSO = CreateObject("Scripting.fileSystemObject")
Set objInputFile = oFSO.OpenTextFile(strOutputFile, _
  OPEN_FILE_FOR_READING)
 
inputData = Split(objInputFile.ReadAll, vbNewline)
 
For each strData In inputData
 
strComputer = strData
 
Set objGroup = GetObject("WinNT://" & strComputer & "/SophosAdministrator")
Set objUser = GetObject("WinNT://Development/" & strUser)
objGroup.Add(objUser.ADsPath)
 
Next

Open in new window

0
 
LVL 14

Expert Comment

by:yehudaha
ID: 23689494
this wil do it

change here as nedd

Set objlist = objfso.OpenTextFile("c:\list.txt", ForReading)
Set objlog = objfso.CreateTextFile("c:\log.txt", ForWriting)

user to add here :
 
strUser = "sharath"

i notice in the script you posted you wrote the group name without space : SophosAdministrator

i wrote it with space so please fix this line if needed:
Set objGroup = GetObject("WinNT://" & strComputer & "/Sophos Administrator")
Const ForReading = 1
Const ForWriting = 2
  
Set objfso = CreateObject("Scripting.FileSystemObject")
Set objlist = objfso.OpenTextFile("c:\list.txt", ForReading)
Set objlog = objfso.CreateTextFile("c:\log.txt", ForWriting)
 
strUser = "sharath"
 
Do Until objlist.AtEndOfStream
strComputer = objlist.ReadLine
If Reachable(strComputer) Then
   If per(strcomputer) Then
Set objGroup = GetObject("WinNT://" & strComputer & "/Sophos Administrator")
Set objUser = GetObject("WinNT://" & strComputer & "/" & strUser)
On Error Resume Next
objGroup.Add(objUser.ADsPath)
If Err.Number = 0 Then
    Err.Clear
    objlog.WriteLine "user added on " & strcomputer & vbCrLf
    On Error Goto 0
    Else
    Err.Clear
    objlog.WriteLine "error adding the user on " & strcomputer & vbCrLf
    On Error Goto 0
End if
Else
objlog.WriteLine "you don't have permission on " & strcompuer & vbcrlf
End If
Else
objlog.WriteLine strcomputer & " is not 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
 
Function per(computer)
        strcomputer = computer
        On Error Resume Next
        Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
        If err.number <> 0 Then
                err.Clear
                per = False
                On Error goto 0
        Else
                per = True
                On Error goto 0
        End If
End Function

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 23691290
I get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add User To All Machines.vbs
Line:      15
Char:      1
Error:      The group name could not be found.
Code:      800708AC
Source:       (null)

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

I tried changing the group name also
0
 
LVL 11

Author Comment

by:bsharath
ID: 23691292
I get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add User To All Machines.vbs
Line:      15
Char:      1
Error:      The group name could not be found.
Code:      800708AC
Source:       (null)

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

I tried changing the group name also
0
 
LVL 14

Expert Comment

by:yehudaha
ID: 23691371
please notice if the group name have space or not
0
 
LVL 14

Expert Comment

by:yehudaha
ID: 23691377
happens to the first machine ?
0
 
LVL 11

Author Comment

by:bsharath
ID: 23691406
I just put 1 machine it gave this error.
The log file is empty. I tried with and without space but the group anme is without space
0
 
LVL 11

Author Comment

by:bsharath
ID: 23691409
I just put 1 machine it gave this error.
The log file is empty. I tried with and without space but the group anme is without space
0
 
LVL 14

Accepted Solution

by:
yehudaha earned 2000 total points
ID: 23691670
or god i'm so sorry i did salad

a new line to change added

DomainName = "pcchief"

add only you doamin name without com or net extension
Const ForReading = 1
Const ForWriting = 2
  
Set objfso = CreateObject("Scripting.FileSystemObject")
Set objlist = objfso.OpenTextFile("c:\list.txt", ForReading)
Set objlog = objfso.CreateTextFile("c:\log.txt", ForWriting)
 
strUser = "script"
DomainName = "pcchief"
 
Do Until objlist.AtEndOfStream
strComputer = objlist.ReadLine
If Reachable(strComputer) Then
   If per(strcomputer) Then
Set objGroup = GetObject("WinNT://" & strComputer & "/SophosAdministrator")
Set objUser = GetObject("WinNT://" & DomainName & "/" & strUser)
On Error Resume Next
objGroup.Add(objUser.ADsPath)
If Err.Number = 0 Then
    Err.Clear
    objlog.WriteLine "user added on " & strcomputer & vbCrLf
    On Error Goto 0
    Else
    Err.Clear
    objlog.WriteLine "error adding the user on " & strcomputer & vbCrLf
    On Error Goto 0
End if
Else
objlog.WriteLine "you don't have permission on " & strcompuer & vbcrlf
End If
Else
objlog.WriteLine strcomputer & " is not 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
 
Function per(computer)
        strcomputer = computer
        On Error Resume Next
        Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
        If err.number <> 0 Then
                err.Clear
                per = False
                On Error goto 0
        Else
                per = True
                On Error goto 0
        End If
End Function

Open in new window

0
 
LVL 11

Author Comment

by:bsharath
ID: 23691754
Should i change
strUser = "administrator"
Development = "administrator"


I get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add User To All Machines.vbs
Line:      16
Char:      1
Error:      0x80005000
Code:      80005000
Source:       (null)

---------------------------
OK  
---------------------------
0
 
LVL 11

Author Comment

by:bsharath
ID: 23691756
Should i change
strUser = "administrator"
Development = "administrator"


I get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add User To All Machines.vbs
Line:      16
Char:      1
Error:      0x80005000
Code:      80005000
Source:       (null)

---------------------------
OK  
---------------------------
0
 
LVL 14

Expert Comment

by:yehudaha
ID: 23691776
what is this Development = "administrator" ?

as i wrote

user to add can be

strUser = "administrator"

domain name
DomainName = "pcchief"

don't change nothing else i didn't use Development variable in the script


0
 
LVL 11

Author Comment

by:bsharath
ID: 23691840
Sorry my mistake

I get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add user to the administrators group.vbs
Line:      16
Char:      1
Error:      The network path was not found.
Code:      80070035
Source:       (null)

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

For 1 machine it worked perfect
0
 
LVL 11

Author Comment

by:bsharath
ID: 23691841
Sorry my mistake

I get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add user to the administrators group.vbs
Line:      16
Char:      1
Error:      The network path was not found.
Code:      80070035
Source:       (null)

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

For 1 machine it worked perfect
0
 
LVL 14

Expert Comment

by:yehudaha
ID: 23691898
what's diffrent in this machine ?

another domain ? workgroup ? non xp os ? non english os
0
 
LVL 14

Expert Comment

by:yehudaha
ID: 23691908
maybe the group not exist on this machine ?
0
 
LVL 11

Author Comment

by:bsharath
ID: 23691969
Its a vista machine
0
 
LVL 11

Author Comment

by:bsharath
ID: 23691970
Its a vista machine
0
 
LVL 14

Expert Comment

by:yehudaha
ID: 23691988
the user you trying to add not there or your syntax in this line not good:

DomainName = "pcchief" -- >> good

example

DomainName = "pcchief.com"  --> not good
DomainName = "pcchie "  -- > not good  forgot to write the f

and so on
0
 
LVL 14

Expert Comment

by:yehudaha
ID: 23692028
try remove the vista machines i'm checking it
0
 
LVL 11

Author Comment

by:bsharath
ID: 23692135
Thank U worked perfect sorry for the confusion
0
 
LVL 11

Author Comment

by:bsharath
ID: 23692533
Sorry to get back on this

For all i get this

error adding the user on BP-DCT
error adding the user on BP-DCT2

I have these 2 lines changed

strUser = "administrator"    (This being the user i want to add)
DomainName = "development"  (Domain name)
0
 
LVL 11

Author Comment

by:bsharath
ID: 23692534
Sorry to get back on this

For all i get this

error adding the user on BP-DCT
error adding the user on BP-DCT2

I have these 2 lines changed

strUser = "administrator"    (This being the user i want to add)
DomainName = "development"  (Domain name)
0
 
LVL 11

Author Comment

by:bsharath
ID: 23700566
Any luck on this
0
 
LVL 11

Author Comment

by:bsharath
ID: 23702331
Just a remonder incase you missed this
0
 
LVL 11

Author Comment

by:bsharath
ID: 23704363
This is trhe error i get

---------------------------
Windows Script Host
---------------------------
Script:      C:\Add User To All Machines.vbs
Line:      16
Char:      1
Error:      The group name could not be found.
Code:      800708AC
Source:       (null)

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

Can this be logged and proceeded further
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses
Course of the Month18 days, 11 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question