Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stopping Services across multiple servers in parallel

Status
Not open for further replies.

kpandya

Technical User
Oct 16, 2008
2
GB
Hi Guys,

Just after some help / pointers in the right direction. I have a script that based on a Oracle SQL query will stop / start services across multiple servers as follows:

on error resume next

Dim CR: CR = chr(13)

Dim connectionString: connectionString = "Driver={Microsoft ODBC for Oracle};Server=.....

Dim connection: Set connection = CreateObject("ADODB.Connection")

Dim rows: Set rows = CreateObject("ADODB.Recordset")

Dim ObjWMIService, objItem, ObjService, strComputer, strService, ColListOfServices

connection.Open connectionString

Set rows = connection.Execute ("SELECT SERVICENAME, PSIP from MM_APPS_ADMIN.SERVICES where system = 'Test' and active = 'PRIMARY' and section not in ('DISTRIBUTORS') order by priority desc")

Do Until rows.EOF

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & rows("PSIP") & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery("Select * from Win32_Service Where Name ='"& rows("SERVICENAME") & "'")

For Each objService in colListOfServices

objService.StopService()
objService.ChangeStartMode("Manual")

Next
WScript.Echo "Your "& rows("SERVICENAME") & " service has Stopped"
rows.MoveNext
loop

connection.Close
Set rows = Nothing
Set connection = Nothing


The problem I have is that as the script runs in a serial fashion it takes tool long to stop the 200 odd services across all servers.

I want to be able to stop or start services across the server list in parralel so multiple services are stopping over all servers at once.

I assumed I should use an array but having problem getting recordset data into the array and not sure how to pass the array into the WMI commands...

I tried something as below and although the data is present in the array not sure where to go next or how to pass it on:


on error resume next

Dim CR: CR = chr(13)

Dim connectionString: connectionString = "Driver={Microsoft ODBC for Oracle};Server=...;Pwd=sysread;"

Dim connection: Set connection = CreateObject("ADODB.Connection")

Dim rows: Set rows = CreateObject("ADODB.Recordset")

Dim ObjWMIService, objItem, ObjService, strComputer, strService, ColListOfServices

connection.Open connectionString

Set rows = connection.Execute ("SELECT PSIP, SERVICENAME from MM_APPS_ADMIN.SERVICES where system = 'Test' and active = 'PRIMARY' and section not in ('DISTRIBUTORS')")

Dim arrRecordArray

arrRecordArray = rows.GetRows(, , Array("PSIP"), ("SERVICENAME"))

rows.MoveFirst

Dim iRowLoop, iColLoop

For iRowLoop = 0 To UBound(arrRecordArray, 2) ' Total No Of Rows

For iColLoop = 0 To UBound(arrRecordArray, 1) ' Total No Of Cols

For Each strComputer in iColLoop

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & iColLoop & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery("Select * from Win32_Service Where Name ='"& iRowLoop & "'")

Loop

For Each objService in colListOfServices

objService.StopService()

Next

WScript.Echo "Your "& iRowLoop & " services has Stopped"

Next 'iColLoop
Next 'iRowLoop

connection.Close
Set rows = Nothing
Set connection = Nothing



Any ideas, suggestions greatly appreciated!
 
VBScript is fairly linear by nature. To get around this, you can spawn off additional scripts to perform additional tasks.

So as you loop through the record set, simply pass the information needed to another script as command line parameters using the oShell.Run method. Unfortunately, once you've created the child processes, you lose visibility from the parent, so you will have to have some sort of logging in the children that the parent can search for after they terminate.

PSC

Governments and corporations need people like you and me. We are samurai. The keyboard cowboys. And all those other people out there who have no idea what's going on are the cattle. Mooo! --Mr. The Plague, from the movie "Hackers
 
Thanks for the reply PSC, I will look into oShell.Run. So when you mention "you lose visibility from the parent" does this mean all variables will have to be redeclared, just trying to understand how I will pass the service names to be restarted from the parent to child. Trying to keep it a flexi as possible as services move around servers quite a lot so can't really "hard code" anything.

 
VBscript can't multi-thread, to achieve what you want to do you should use .NET or Powershell (which in effect is pretty much .NET as well) and use the threading functionality that gives you.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top