Avatar of Yashy
Yashy
Flag for United Kingdom of Great Britain and Northern Ireland asked on

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

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
Windows BatchShell ScriptingWindows Server 2003

Avatar of undefined
Last Comment
Yashy

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Kimputer

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Yashy

ASKER
Thank you Kimputer.

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

If run on the server as an admin, username passwords are not an issue.
SOLUTION
serialband

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Yashy

ASKER
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?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
serialband

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.
Yashy

ASKER
Thank you guys for the help.