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.

techraf
  • 4,343
Kennet
  • 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. – JosefZ Sep 05 '16 at 15:08

1 Answers1

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}}
  • 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 – Kennet Sep 07 '16 at 06:33
  • I have edited the commands . Please test it again . – Elton Ji - MSFT Sep 08 '16 at 06: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
    – Kennet Sep 09 '16 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. – Kennet Sep 09 '16 at 12:40