Question

Is there an easy way to verify all files were copied correctly when calling copy-item? I thought about using the checksum on all files, but I would imagine powershell (v2) would already have something, and I can't find it.

Was it helpful?

Solution

No there isn't and here is why. Copy-Item is a generic cmdlet that works for all namespace providers. So the items being copied could be files, or registry settings, or IIS configuration sections, etc. Verifying a file copy is quite a bit different than verifying a copy of registry settings.

UPDATE: As pointed out by @Dave_S the XCOPY command's verification switch isn't the kind of verification you are looking for.

If you are copying text files you could use the PowerShell Compare-Object commandlet.

If you are copying binary files you could use the system fc.exe command with /b switch.

OTHER TIPS

I know it's an old thread, but I thought I'd post this just in case anyone else is reading it... the /v switch DOES NOT verify the data! It just makes sure that the copy is readable. See http://support.microsoft.com/kb/126457 for details.

My current favourite solution is xcopy in combination with a hashdeep audit. Can be packed together in a small BAT-file.

Just an update, Powershell v4 includes Get-FileHash which can be used to verify a file was copied successfully. If the hash is the same, the file has been copied successfully. Link to TechNet Library.

I use this answer to come up with the following.

(Get-ChildItem -file -path c:\files -Recurse).FullName | foreach {get-filehash $_ -Algorithm md5} Also can be piped into Export-CSV to easily visually compare the file hashes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top