?
Solved

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

Posted on 2016-09-08
7
Medium Priority
?
437 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 36

Accepted Solution

by:
Kimputer earned 1600 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 36

Expert Comment

by:Kimputer
ID: 41789284
If run on the server as an admin, username passwords are not an issue.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 30

Assisted Solution

by:serialband
serialband earned 400 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 30

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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

A quick step-by-step overview of installing and configuring Carbonite Server Backup.
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…
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…
Suggested Courses

765 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