We help IT Professionals succeed at work.

SC Query Script to only show service name and state

CMILLER
CMILLER asked
on
84 Views
Last Modified: 2018-10-08
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?
Comment
Watch Question

Qlemo"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015

Commented:
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

CMILLERCyber Security

Author

Commented:
How do I use that for one service? the service I am looking for in the "Windows Agent Service"
CMILLERCyber Security

Author

Commented:
and how do I add a list of computernames ?
"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions