0

I need to compare the content of files on 2 different machines. There are around 50 files in the folder on each PC. So far I have done this:

compare (gc \\PC1\d$\Data\Config\*) (gc \\PC2\d$\Data\Config\*) | Out-GridView 

and it works fine, but in that way I can't see in which file the difference exist. So I need the filename in the result.

1
  • gc \\PC1\d$\Data\Config\* returns unstructured array of lines from all files in \\PC1\d$\Data\Config folder; the same holds for gc \\PC2\d$\Data\Config\*. Therefore you can't grab filenames. You need to compare individually, file by file taken from Get-ChildItem cmdlet. Commented Sep 5, 2016 at 15:08

1 Answer 1

0

If files under folder "...\Config" are same . You may need to compare with each file :

Edited:

Get-ChildItem \\PC1\d$\Data\Config\* | %{$path1 = "\\PC1\d$\Data\Config\$($_.name)" ;$path2 = "\\PC2\d$\Data\Config\$($_.name)" ; $dif = compare (gc $path1) (gc $path2);if ($dif) {$_.name;$dif}} 
4
  • Files should be the same, because these Point-Of-Sale PC's are made from the same image, but the content of the files is not totally the same. But this doesn't seem to work. I have replaced \\PC1\..... with the original destination. I get this error: Compare-Object : Cannot bind argument to parameter 'ReferenceObject' because it is null. At line:1 char:106 Commented Sep 7, 2016 at 6:33
  • I have edited the commands . Please test it again . Commented Sep 8, 2016 at 6:19
  • Well I can see in which files the difference is, and I can see the difference, but I still have a lot this: Compare-Object : Cannot bind argument to parameter 'ReferenceObject' because it is null. At line:1 char:261 + ... $dif = compare (gc $path1) (gc $path2);if ($dif) {$_.name;$dif}} + ~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Compare-Object], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.CompareObjectCommand Commented Sep 9, 2016 at 12:38
  • By the way I have added "-Exclude data" because it's folder with limited access to and it will fail everytime, but it's not important. Commented Sep 9, 2016 at 12:40

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.