Run a command against a set of servers

  • Thread starter Thread starter Hassan
  • Start date Start date
H

Hassan

I want to be able to run a command against a set of servers.

Say I have 4 servers

ServerA, ServerB,ServerC and ServerD

So I want to run a command such as

msinfo32 /computer [ServerName]

where servername would be those 4 servers. Can you just provide a generic
script for me that i could use?

Pseudo code

For { List of Servers}
do
{command [Servername]}

I just want to get started and I hope to add on to whatever example you can
provide..

Thanks
 
Hassan said:
I want to be able to run a command against a set of servers.

Say I have 4 servers

ServerA, ServerB,ServerC and ServerD

So I want to run a command such as

msinfo32 /computer [ServerName]

where servername would be those 4 servers. Can you just provide a generic
script for me that i could use?

Pseudo code

For { List of Servers}
do
{command [Servername]}

I just want to get started and I hope to add on to whatever example you can
provide..

Thanks

Try this:

for %a in (Server1 Server2 Server3 Server4) do msinfo32 /computer %a
(from a Command Prompt)

@echo off
for %%a in (Server1 Server2 Server3 Server4) do msinfo32 /computer %%a
(in a batch file)

@echo off
for /F %%a in (c:\Servers.txt) do msinfo32 /computer %%a
(Reading server names from a list file)
(from a Command Prompt)
 
Cool.. Will give that a shot.. thats a good start for me..


Pegasus (MVP) said:
Hassan said:
I want to be able to run a command against a set of servers.

Say I have 4 servers

ServerA, ServerB,ServerC and ServerD

So I want to run a command such as

msinfo32 /computer [ServerName]

where servername would be those 4 servers. Can you just provide a generic
script for me that i could use?

Pseudo code

For { List of Servers}
do
{command [Servername]}

I just want to get started and I hope to add on to whatever example you can
provide..

Thanks

Try this:

for %a in (Server1 Server2 Server3 Server4) do msinfo32 /computer %a
(from a Command Prompt)

@echo off
for %%a in (Server1 Server2 Server3 Server4) do msinfo32 /computer %%a
(in a batch file)

@echo off
for /F %%a in (c:\Servers.txt) do msinfo32 /computer %%a
(Reading server names from a list file)
(from a Command Prompt)
 
Back
Top