Link to home
Start Free TrialLog in
Avatar of Chris Miller
Chris MillerFlag for United States of America

asked on

SC Query Script to only show service name and state

CN.txt - List of computernames
services.txt - list of services to check

@echo off
 for /f %%a in (CN.txt) do (
   echo %%a >> Output.txt
   for /f "tokens=*" %%b in (services.txt) do (
     sc \\%%a query "%%~b" >> Output.txt
   )
 )
 pause

How do I clean this script up to only show the Service_Name and state?
Avatar of Qlemo
Qlemo
Flag of Germany image

It is a bad idea to try to parse sc output that way, because it needs too much effort. Just use PowerShell instead, e.g.
powershell "get-service | format-table -auto name, status"

Open in new window

or
powershell "get-service | Select name, status | Out-File Output.txt"

Open in new window

Avatar of Chris Miller

ASKER

How do I use that for one service? the service I am looking for in the "Windows Agent Service"
and how do I add a list of computernames ?
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial