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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to check services in remote servers

Status
Not open for further replies.

ChinkoNinja

Technical User
Jun 27, 2012
2
CA
Hi,

I'm a new scripting so please bear with me.

I need a simple script to:
1) Get a list of services on remote Windows servers (from a txt file, e.g., serverlist.txt) that are associated with a specific "Logon Account"
2) Then pipe the result into a text file.

For example:
I need to find services on servers that has a StartName (Logon As) of "NT Authority\NetworkService"

So the result should be similar to:
service-list.txt (sample name of output file)

Servername: SERVER0001

Name StartName
---- ---------
RpcSs NT AUTHORITY\NetworkService
Dhcp NT AUTHORITY\NetworkService
aspnet_state NT AUTHORITY\NetworkService
Dnscache NT AUTHORITY\NetworkService
MSDTC NT AUTHORITY\NetworkService
LicenseService NT AUTHORITY\NetworkService


Servername: SERVER0002

Name StartName
---- ---------
MSSQLServerADHelper NT AUTHORITY\NetworkService
MsDtsServer NT AUTHORITY\NetworkService
RpcLocator NT AUTHORITY\NetworkService
SysmonLog NT Authority\NetworkService

Any help would be GREATLY appreciated.

Thank you!
 
What have you tried so far and where in your code are you stuck ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
As a starting point, the script below will show a bunch of information for each service installed on your local workstation. See if the "StartName" property gives the information you want. Change the value of strComputer from "." to the name of a remote server to access services there. (your script will need to be run with credentials that have sufficient rights on the remote server)

When you can get the information you want, look into the FileSystem Object to read your input file (list of servers), and loop for each server name.

Code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Service",,48)
For Each objItem in colItems
    Wscript.Echo "AcceptPause: " & objItem.AcceptPause
    Wscript.Echo "AcceptStop: " & objItem.AcceptStop
    Wscript.Echo "Caption: " & objItem.Caption
    Wscript.Echo "CheckPoint: " & objItem.CheckPoint
    Wscript.Echo "CreationClassName: " & objItem.CreationClassName
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "DesktopInteract: " & objItem.DesktopInteract
    Wscript.Echo "DisplayName: " & objItem.DisplayName
    Wscript.Echo "ErrorControl: " & objItem.ErrorControl
    Wscript.Echo "ExitCode: " & objItem.ExitCode
    Wscript.Echo "InstallDate: " & objItem.InstallDate
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "PathName: " & objItem.PathName
    Wscript.Echo "ProcessId: " & objItem.ProcessId
    Wscript.Echo "ServiceSpecificExitCode: " & objItem.ServiceSpecificExitCode
    Wscript.Echo "ServiceType: " & objItem.ServiceType
    Wscript.Echo "Started: " & objItem.Started
    Wscript.Echo "StartMode: " & objItem.StartMode
    Wscript.Echo "StartName: " & objItem.StartName
    Wscript.Echo "State: " & objItem.State
    Wscript.Echo "Status: " & objItem.Status
    Wscript.Echo "SystemCreationClassName: " & objItem.SystemCreationClassName
    Wscript.Echo "SystemName: " & objItem.SystemName
    Wscript.Echo "TagId: " & objItem.TagId
    Wscript.Echo "WaitHint: " & objItem.WaitHint
Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top