?
Solved

Run command/exe to serverlist.

Posted on 2013-01-31
10
Medium Priority
?
362 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 56

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 56

Accepted Solution

by:
Bill Prew earned 2000 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

Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

Question has a verified solution.

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

The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Suggested Courses

752 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