r/PowerShell • • Nov 27 '20

Question A PowerShell script that can copy one folder (with 700 folders, and 50,000 files) to another folder - and produce a detailed timestamped log of the copying process?

Hi,

Is there a PowerShell script that can copy one folder (with 700 folders, and 50,000 files) to another folder - and produce a detailed timestamped log of the copying process?

Can anyone provide a script that can do this please? :)

0 Upvotes

17 comments sorted by

50

u/krzydoug Nov 27 '20

Robocopy

6

u/themastermatt Nov 27 '20

This is the way. We use robocopy scripts to migrate entire file servers and produce a log file. Can even leave it running with the sync option and keep the source and destination up to date. I've migrated 6TB CIFS shares with it. Very powerful.

2

u/DataDuude Nov 27 '20

Hi! I agree, but the thing is when I use RoboCopy the total size does not match up.

I posted about it here: https://old.reddit.com/r/sysadmin/comments/k1pc5u/trying_to_use_robocopy_to_copy_one_folder/

The problem is I just don't know enough to know how to get it to copy files and be exactly the same size.

10

u/themastermatt Nov 27 '20

I guess more is better than less lol. I've found robo copy can see more than your account might have permission to read. When your calculating total folder size, you may be missing things where you're explicitly denied, but robocopy will snag that data. Do file and folder counts match? Ignore data set size and focus on number of items. Too much can skew size on disk.

4

u/Jenjenmi Nov 27 '20

Are your sizes different because the drives aren’t formatted identically? NTFS/FAT32? MBR/GOt?There’s one more choice I can’t remember the name of, default sector size maybe?

2

u/Aertheron01 Nov 27 '20

Never had issues with robocopy, and as others have said, size isn't a good indicator, look at item count for files and folders.

2

u/BlackV Nov 28 '20

people gave you a bunch or correct answers in that thread too

did you try any of the suggestions?

why do you care id the size is different if you know all the files and folders are there?

get-childitem on teh source
get-childitem on the dest
compare-object on source and dest is it equal?

or

get-filehash on source
get-filehash on dest
compare-object on source and dest is it equal?

get-childitem, get-date, compare-object, get-filehash, copy-item, robocopy are all the tools you need

1

u/jantari Nov 30 '20

And did you read the top comment/response to your question there?

There is no better way to copy files and directories than robocopy, forget it. If robocopy isn't working right it's because you're doing something wrong.

3

u/[deleted] Nov 27 '20

2

u/[deleted] Nov 27 '20

If you choose robocopy, take a look at the compress parameter.

It's new in the latest release and also integrated in the sms extension in windows admin center.

1

u/nostril_spiders Nov 27 '20

...is the correct answer, but may I suggest the following:

Find-Module -Tag Robocopy

I'm on mobile and haven't checked myself, but I assume someone has written a powershell interface for it by now, which would help with the tricky parameters

2

u/emJayDunn Nov 27 '20

Try free file sync

1

u/[deleted] Nov 27 '20

Get-childitem and Copy-item usually works fine.

1

u/dasookwat Nov 27 '20

this is where robocopy comes in. it's anot a powershell toopl, but a commandline tool, and you can still call it from a ps script if you want.

1

u/ExeqZ Nov 27 '20

Take totalcommander. With that you dont have Problem with Rights or long path names.

2

u/BlackV Nov 28 '20

wow that's a name i've not heard in about 10 years, is it still around

1

u/Super_Art_23 Nov 28 '20

Does the number of files and or folders match up? Use Beyond Compare like I mentioned in the other post. It will tell you exactly where your differences are.