Solved

Run command/exe to serverlist.

Posted on 2013-01-31
10
346 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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

Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
A procedure for exporting installed hotfix details of remote computers using powershell
The viewer will learn how to dynamically set the form action using jQuery.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

838 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