Solved

Run command/exe to serverlist.

Posted on 2013-01-31
10
317 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
 
LVL 52

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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

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 52

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

929 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now