Solved

Psexec - a script to use Psexec to copy a folder from one server to multiple PC's?

Posted on 2016-09-08
7
124 Views
Last Modified: 2016-09-12
Hi guys,

I've got a script here that OdBA created for me a while back which was to execute a .msi file from a shared location on our server to multiple PC's using the Psexec command.

Here it is:

@echo off
setlocal enabledelayedexpansion
set MachineFile=C:\Temp\machines.txt
set LogFile=C:\Temp\machines.csv
>"%LogFile%" echo "Machine","State","Errorlevel"
for /f %%a in ('type "%MachineFile%"') do (
      echo Processing %%a ...
      ping.exe -4 -n 2 %%~a | find /i "TTL" >NUL
      if errorlevel 1 (
            >>"%LogFile%" echo "%%~a","Offline","n/a"
      ) else (
            ECHO c:\psexec.exe \\%%~a -u Domain\Username -p Password msiexec.exe /i "\\networkservername\sharename\my.msi" /quiet /norestart
            >>"%LogFile%" echo "%%~a","Online","!ErrorLevel!"
      )
)
echo Done.


Is there a way to modify this so that it can copy a folder from the server share, to a folder on PC's with different IP's?

Thanks a lot
Yashy
0
Comment
Question by:Yashy
  • 3
  • 2
  • 2
7 Comments
 
LVL 35

Accepted Solution

by:
Kimputer earned 400 total points
ID: 41789275
If the script is run from a server with domain connected pc's, yes, the script can be modified to do that.
the echo command should be replaced with something like

xcopy  \\server\share\folder\*.*  \\%%~a\c$\temp /e
0
 
LVL 1

Author Comment

by:Yashy
ID: 41789278
Thank you Kimputer.

So in terms of the username/password details of the domain, will that still remain?
0
 
LVL 35

Expert Comment

by:Kimputer
ID: 41789284
If run on the server as an admin, username passwords are not an issue.
0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
LVL 29

Assisted Solution

by:serialband
serialband earned 100 total points
ID: 41789988
You really shouldn't place plain text passwords in a script.  It's better to use runas to elevate your scirpt or place your script into the scheduler and have the run as user setting enabled.

If you have large folders, of several gigabyte or many files, I would replace xcopy with robocopy, so that you can more easily continue interrupted copies.

robocopy.exe  \\server\share\folder\*.*  \\%%~a\c$\temp /mir
0
 
LVL 1

Author Comment

by:Yashy
ID: 41790911
If I wanted to remove the username/password, can I remove this:

c:\psexec.exe \\%%~a -u Domain\Username -p Password msiexec.exe /i "\\networkservername\sharename\my.msi" /quiet /norestart

And replace it with

robocopy.exe \\server\share\folder*.* \\%%~a\c$\temp?
0
 
LVL 29

Expert Comment

by:serialband
ID: 41791298
Yes.  Even with the psexec.exe, the whole script can be placed in a scheduled tasked with the credentials as a run once task.  That way the password isn't stored in plain text.  I would always avoid using plain text passwords where I can.
0
 
LVL 1

Author Closing Comment

by:Yashy
ID: 41793955
Thank you guys for the help.
0

Featured Post

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Convert grep lines to perl 6 58
Generate HTML report about DHCP server 2003 1 45
ticket bloat 3 49
AWK use math to add new field - single file 5 35
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Learn about cloud computing and its benefits for small business owners.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

808 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