Get the all the SQL Server related services information

,

'
'====================================================================
'Purpose : get the all the SQL Server related services information.
'
'Author : Satyanarayana B
'Created on: 10/11/2008
'
'Input : Servers.txt (Create the servers list in the text file
' and place at current folder).
'Output : Service_list.csv file in the current folder
'
'Usage : cscript service.vbs
'====================================================================
'

Input :== Servers text file

===================

Server1

Server2

Output :== Service_list.csv

====================

System Name, Service Name, Service State, Caption, Start Mode, Account Name
Server1,MSSQLSERVER,Running,MSSQLSERVER,Auto,Domain\User,
Server1,MSSQLServerADHelper,Stopped,MSSQLServerADHelper,Manual,LocalSystem,
Server1,MSSQLServerOLAPService,Running,MSSQLServerOLAPService,Auto,Domain\User,

Server2,MSSQLSERVER,Running,MSSQLSERVER,Auto,Domain\User,
Server2,MSSQLServerADHelper,Stopped,MSSQLServerADHelper,Manual,LocalSystem,
Server2,MSSQLServerOLAPService,Running,MSSQLServerOLAPService,Auto,Domain\User,

'
'====================================================================
'Purpose : get the all the SQL Server related services information.
'
'Author : Satyanarayana B
'Created on: 10/11/2008
'
'Input : Servers.txt (Create the servers list in the text file 
'             and place at current folder).
'Output : Service_list.csv file in the current folder
'
'Usage : cscript service.vbs
'====================================================================
'
Const ForAppending = 8
Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
 (".\servers.txt", ForReading)

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objLogFile = objFSO.OpenTextFile(".\service_list.csv", _ 
 ForAppending, True)

objLogFile.Write _
 ("System Name, Service Name, Service State, Caption, Start Mode, Account Name ") 
objLogFile.Writeline


Do Until objTextFile.AtEndOfStream
 strComputer = objTextFile.Readline

    Set objWMIService = GetObject("winmgmts:" _
     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colListOfServices = objWMIService.ExecQuery _
     ("Select * from Win32_Service WHERE DisplayName LIKE '%%SQL%%'")
    For Each objService in colListOfServices
     objLogFile.Write(objService.SystemName) & "," 
     objLogFile.Write(objService.Name) & "," 
     objLogFile.Write(objService.State) & "," 
     objLogFile.Write(objService.Caption) & "," 
     objLogFile.Write(objService.StartMode) & "," 
     objLogFile.Write(objService.StartName) & "," 
     objLogFile.writeline
    Next
Loop

objLogFile.Close

Rate

Share

Share

Rate