Forum Discussion
Comparing Files in two Document Libraries with PowerShell
Hi mwilliams71
Here it is an example assuming only one site, please adapt and test because you want to compare a stream
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Variables for Processing
$SourceWebURL = "https://Your-Source-Web-URL"
$SourceLibrary ="Team Docs"
$TargetLibrary = "Shared Documents"
$ColumnToCompare="Your Compare Column Name"
$Web = Get-SPWeb $SourceWebURL
$ListOne = $web.lists[$SourceLibrary]
$ListTwo = $web.lists[$TargetLibrary]
$ListOneValues = @()
$ListTwoValues = @()
$ListOne.Items| foreach { $ListOneValues+= $_[$ColumnToCompare] }
$ListTwo.Items | foreach { $ListTwoValues+= $_[$ColumnToCompare] }
Compare-Object $ListOneValues $ListTwoValues
This may work for initiating the copy file PowerShell script.
- Joao LivioOct 17, 2022Iron ContributorSee link in first reply, have examples
- mwilliams71Oct 17, 2022Brass Contributor
I'm not sure how this will help me when comparing over 2,000 files in one library to another, so that the files can be exact duplicates. I would make changes in say Test Web Application in the asset library and these changes should be copied to the production web application in the asset library. It looks like the code below is only looking for words in one text file.
Compare-Object -ReferenceObject (Get-Content -Path C:\Test\Testfile1.txt) -DifferenceObject (Get-Content -Path C:\Test\Testfile2.txt)
InputObject SideIndicator
----------- -------------
cat =>
racoon =>
dog <=
squirrel <=- Joao LivioOct 17, 2022Iron Contributor
Hi mwilliams71
The SideIndicator simply tell you where is the difference is.
<= Difference is in Left side
first object to compare
=> Difference is in the Right side
Second object in the comparison
My first suggestion was to download, compare and upload.
You have to mix all suggestions and architect your outcome, or wait for more.
Good luck 👍