Solved

Run command/exe to serverlist.

Posted on 2013-01-31
10
306 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 51

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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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 51

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

746 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