Solved

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

Posted on 2016-09-08
7
105 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
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.

 
LVL 28

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 28

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

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

Setting up a Microsoft WSUS update system is free relatively speaking if you have hard disk space and processor capacity.   However, WSUS can be a blessing and a curse. For example, there is nothing worse than approving updates and they just have…
ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.

803 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