Connect with us

Hi, what are you looking for?

Citrix XenApp

How to use Microsoft PsExec and Xcopy to pull data off a large number of remote machines simultaneously

My co-worker and I were in a bit of a pinch recently and had to quickly pull data off a large number of VMs as fast as possible. We had a real time crunch to get it done.

ctrl-c-ctrl-v

Well, Ctrl+C Ctrl+V is one way to do it but you’re better than that. The easier way is to use PsExec and Xcopy/Robocopy to do it. Getting PsExec and Xcopy to play nicely is sometimes a bit tricky. Here’s a really quick and dirty script to get it done. Not the most efficient but it will work in a pinch

1. Copy psexec into a folder on the server you plan to copy your data to. Let’s call this drive D:\DataBackup. Now share it out to Everyone with Read/Write access.

Advertisement. Scroll to continue reading.

2. Create a .bat file with the following. Let’s call it remotescript.bat and let’s say you are after user profile data. So:

Let me explain what it does. Xcopy is invoked to look at the local VM’s name under the c:\Users folder. It then excludes and directories you specify in an excludes.txt file located on the file share you created. Then it copies whatever is left to the file share you created under a directory with the VM’s name. The switches are doing the following

Advertisement. Scroll to continue reading.

/e – Copies all subdirectories, even empty ones
/h – Copies files with hidden and system file attributes
/c – Ignores errors
/y – Suppresses overwrite file confirmation prompts

and when it’s all done exits.

3. Create the excludes.txt file in this same folder. This will contain all the directories you don’t want to copy over. Here’s an example of mine:

Advertisement. Scroll to continue reading.

\All Users
\Administrator
\Public
\Default
\YourServiceAccount1
\YourServiceAccount2
\YourServiceAccount3

You can even do a wildcard where if it begins with something it won’t copy it. For example, if I have several test accounts that all start with “Test_userID” then I would say:

\Test_

Advertisement. Scroll to continue reading.

4. In your file share, create a file called VMnames.txt and have 1 name per line. Pretty simple. Export it from wherever you want and massage the data in Excel if you need to. Text to Columns works wonders.

5. Now open up a cmd prompt and go to the folder you have everything staged so far. Run the following where the user ID has admin rights to the VMs:

Advertisement. Scroll to continue reading.

Now let me explain this. PsExec is invoked and will pass your user ID and password to the remote machines specified in VMnames.txt and run remotescript.bat. Here is what the switches are doing:

/d – Don’t wait for the script to finish running on each VM. Basically you are telling the script to run on all VMs in parallel. Otherwise you’ll be sitting around all day as each VM finishes copying.

/c – Copy the remotescript.bat to the remote machine

Advertisement. Scroll to continue reading.

/f – Force the copy in the event remotescript.bat was already copied to the machine. Comes in handy if you did some testing on a few VMs first before letting the script loose on all the VMs.

Hope this helps. You can also use Robocopy which is what I prefer over Xcopy. Just modify the above accordingly. Here’s a standalone Robocopy script I like to use to copy all files, empty folders, and ACLs while still retaining time stamps. Comes in handy all the time:

Advertisement. Scroll to continue reading.

Here is what the switches mean:

/E – Copy subfolders including empty folders
/ZB – Use restartable mode
/DCOPY:T – Copy file directory timestamps
/COPYALL – Copy all file info (data, attributes, time stamps, ACL, owner info, and auditing info)
/R:1 – Retry failed copies once
/W:1 – Wait 1 second between retries
/V – Verbose logging
/TEE – Writes the status to the console window and to the log file
/LOG: – Specifies log file and will overwrite if there is already one named the same

Advertisement. Scroll to continue reading.
Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like

Apache

Today I would like to go over proper URL redirection when using SSL but first I would like to preface this by describing what...

Exchange 2003

A useful Exchange 2003 guide I wrote for a friend’s blog originally but I am posting it here on mine now for your viewing...

Citrix Workspace

You can use FIDO2 hardware security keys plugged into your physical desktop over the Citrix HDX remoting protocol for use with virtualized Windows Desktop...

Cloud Design Architecture

The community-driven paperback book initiated by my friends Bas van Kaam and Christiaan Brinkhoff is available for sale on Amazon. If you haven’t picked...

Advertisement

JasonSamuel.com was launched in 2008 as a platform to give back to the IT community by sharing knowledge and expertise. Over the years, it has become a trusted global resource for the latest insights, how-to guides, and forward-thinking leadership on enterprise mobility, security, virtualization, cloud architecture, automation, and other cutting-edge technologies. Today, it serves as a go-to reference hub for IT professionals, attracting hundreds of thousands of unique visitors from around the world each month. Learn more on the About Me page.
Copyright © 2008-2025 JasonSamuel.com