Solved

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

Posted on 2016-09-08
7
95 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

863 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

26 Experts available now in Live!

Get 1:1 Help Now