[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

windows scripting question

Posted on 2012-09-18
10
Medium Priority
?
197 Views
Last Modified: 2012-12-21
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
0
Comment
Question by:SANDDRAGON2004
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 83

Accepted Solution

by:
leakim971 earned 300 total points
ID: 38415441
0
 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 38415847
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
 
LVL 11

Expert Comment

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

Open in new window

0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

 
LVL 38

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 38416677
@paul - slight modification, what's the gain? Mine is working as well ;)
0
 
LVL 24

Expert Comment

by:yo_bee
ID: 38418389
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
 

Author Comment

by:SANDDRAGON2004
ID: 38419499
Yes i am running in AD,  i would surely try it will try all the scripts listed. thank you
0
 
LVL 24

Expert Comment

by:yo_bee
ID: 38419653
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
 
LVL 11

Expert Comment

by:paultomasi
ID: 38420225
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

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month20 days, 11 hours left to enroll

865 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question