|
server
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
configure scripts to run against a list of machines
Repository. However, my one question is this. Being a relative newbie to scripting myself, I'm not sure how - of if - I can modify any of the scripts to be run against a list of machine names contained in a text file (instead of strComputer = "."). In particular, I'm looking to change the account name used for a particular service from it's current account to LocalSystem. This is a sample of the script contained in the Portable Script Center to accomplish this on a single machine: strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colServiceList = objWMIService.ExecQuery _ ("Select * from Win32_Service Where StartName = '.\netsvc'") For each objService in colServices errServiceChange = objService.Change _ ( , , , , , , "NT AUTHORITY\LocalService" , "") Next However, I want to run this against a number of machines - of which I already have a text-file list of. Elliott Walker wrote:
Show quote >I have - and love to use - the scripts contained in the Portable Script You can use the FileSystemObject for this. The code would be similar to:> Repository. However, my one question is this. Being a relative newbie to > scripting myself, I'm not sure how - of if - I can modify any of the > scripts > to be run against a list of machine names contained in a text file > (instead > of strComputer = "."). > > In particular, I'm looking to change the account name used for a > particular > service from it's current account to LocalSystem. This is a sample of the > script contained in the Portable Script Center to accomplish this on a > single > machine: > strComputer = "." > Set objWMIService = GetObject("winmgmts:" _ > & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") > > Set colServiceList = objWMIService.ExecQuery _ > ("Select * from Win32_Service Where StartName = '.\netsvc'") > > For each objService in colServices > errServiceChange = objService.Change _ > ( , , , , , , "NT AUTHORITY\LocalService" , "") > Next > > However, I want to run this against a number of machines - of which I > already have a text-file list of. ============== Const ForReading = 1 ' Specify the text file of user names. strFilePath = "c:\Scripts\Computers.txt" ' Open the file for read access. Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile(strFilePath, ForReading) ' Read each line of the file. Do Until objFile.AtEndOfStream strComputer = Trim(objFile.ReadLine) ' Skip blank lines. If (strComputer <> "") Then ' Do whatever for each computer. Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" _ & strComputer & "\root\cimv2") Set colServiceList = objWMIService.ExecQuery _ ("Select * from Win32_Service Where StartName = '.\netsvc'") For each objService in colServices errServiceChange = objService.Change _ ( , , , , , , "NT AUTHORITY\LocalService" , "") Next End If Loop ' Clean up. objFile.Close |
|||||||||||||||||||||||