Solved

Run command/exe to serverlist.

Posted on 2013-01-31
10
338 Views
Last Modified: 2013-02-12
Hi,

I’d need to a run some  commands and an exe to different servers. I have a list of this servers.
How can I do this without typing the name of the server in each command line?

Please advise.
J.
0
Comment
Question by:janhoedt
  • 5
  • 2
10 Comments
 
LVL 7

Expert Comment

by:karunamoorthy
ID: 38839548
You can try some commercial patch management soft wares like Active Directory for this purpose.
0
 

Author Comment

by:janhoedt
ID: 38839631
No, I need to do it via powershell or vbscript.
0
 

Author Comment

by:janhoedt
ID: 38839710
I found a powershellscript but need some help with it:

http://gallery.technet.microsoft.com/scriptcenter/59e314fc-3d4b-42bc-9769-fd60c20070a5

Where do I put my serverlist and command exactly?
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 53

Expert Comment

by:Bill Prew
ID: 38842264
You can do this right from the command line or a BAT file using the Microsoft psexec utility.

See these prior questions for info and examples.

http://www.experts-exchange.com/Software/Misc/Q_22972076.html

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Q_22397407.html

~bp
0
 

Author Comment

by:janhoedt
ID: 38842967
I have already the psexec running.
Problem is I have to run a 64 or 32 bit exe remotely, depending on the OS-version, then collecting the output. Would also like a logfile to see what failed (machines which are not running f.e.).

Can you help me with that?

Code I have for psexec:
for /f %A in (c:\temp\serverlist.txt) do psexec \\%A c:\windows\temp\myexecutable.exe /q
0
 
LVL 53

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 38843578
This feels like it should be pretty close to what you are looking for. Of course depending on your server mix some could have problems with the WMI or PSEXEC calls, since they rely on RPC being active, and the right security, etc.

@echo off
setlocal

REM Define files to be used
set ServerList=c:\temp\servers.txt
set LogFile=c:\temp\log.txt

REM Capture all output to a log file
(
  REM Read each server name from the file
  for /F "usebackq tokens=* delims=" %%A in ("%ServerList%") do (
    REM Do a basic ping to server to make sure it responds
    ping -n 1 -w 250 %%A >nul 2>nul && (
      REM Use WMI to get the architecture of the remote server
      for /F "tokens=2 delims=, skip=1" %B in ('wmic os get osarchitecture^,version /format:csv') do (
        REM Use different command on 64 versus 32 bit OS
        if "%%B" == "64-bit" (
          psexec \\%%A c:\windows\temp\myexecutable64.exe /q
        ) else (
          psexec \\%%A c:\windows\temp\myexecutable32.exe /q
        )
    ) || (
      REM Ping failed, log as unreachable
      echo Server [%%A] not reachable
    )
  )
) >"%LogFile% 2>&1"

Open in new window

~bp
0
 

Author Comment

by:janhoedt
ID: 38847349
Thanks! i ll check asap!
0
 

Author Comment

by:janhoedt
ID: 38854084
Sorry billprew, still didn't had the time, but already thanks a lot for your effort.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

This article will help you understand what HashTables are and how to use them in PowerShell.
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

803 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