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