windows scripting question

I need to create a script that will do the following on 300 windows servers.

pull from a file "serverlist.txt"

log onto each server in the serverlist.txt file and run a command to list all running services.
export that list to a file name "\\server\folder\filename-servername.txt
SANDDRAGON2004Asked:
Who is Participating?
 
Gerwin Jansen, EE MVETopic Advisor Commented:
On a command line:
for /f %f in (serverlist.txt) do sc "\\%f" query > "\\server\folder\filename_%f.txt"

Open in new window

serverlist.txt contains 1 server name on each line, admin rights are needed so you can remotely query the running services (sc query default shows running services).

If you want to put above command in a script, change %f to %%f (3 times).
0
 
Paul TomasiCommented:
for /f "usebackq" %%a in ("serverlist.txt") do (
  sc "\\%a" query >"\\server\folder\filename-%%a.txt"
)

Open in new window

0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
Gerwin Jansen, EE MVETopic Advisor Commented:
@paul - slight modification, what's the gain? Mine is working as well ;)
0
 
yo_beeDirector of Information TechnologyCommented:
Do you have AD. I have a script that will query AD for any Server Objects and gather anything you want from the machine leveraging WMI.

Does that sound like something you might want to try?
0
 
SANDDRAGON2004Author Commented:
Yes i am running in AD,  i would surely try it will try all the scripts listed. thank you
0
 
yo_beeDirector of Information TechnologyCommented:
What are you looking to get out of this report?
To query 300 Servers and all their services while a pretty large report and the formating will be something you will want to think about.
0
 
Paul TomasiCommented:
Oops! Missed a '%' sign off the FOR-variable. Here it is again:

for /f "usebackq" %%a in ("serverlist.txt") do (
  sc "\\%%a" query >"\\server\folder\filename-%%a.txt"
)
 

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.