Solved

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

Posted on 2016-09-08
7
72 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 27

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 27

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

A quick step-by-step overview of installing and configuring Carbonite Server Backup.
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

708 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

21 Experts available now in Live!

Get 1:1 Help Now