Oct 14 2022 07:17 AM
I have 30 files with code in a library in a web application imbedded in sub folders that I want to compare to another 30 files with code in a library in a separate web application in sub folders. If any code is different in the first document library than the second document library, I would Like to run a PowerShell script to copy the changed files and over-write the files with the same name in the second document library.
I have this code so far from: Copy Files Between Document Libraries in SharePoint using PowerShell - SharePoint Diary
Thanks for the help,
Michael Williams
Oct 14 2022 02:01 PM
Hi @mwilliams71
Just an idea, in your case first I will download the stream, and by the Microsoft.PowerShell.Utility I'll compare both files.
Compare-Object (Microsoft.PowerShell.Utility) - PowerShell | Microsoft Learn
Oct 14 2022 02:17 PM
Oct 14 2022 02:38 PM - edited Oct 14 2022 02:41 PM
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
Oct 14 2022 06:56 PM
The code here should help you to compare 2 files:
https://devblogs.microsoft.com/scripting/use-powershell-to-compare-two-files/
Oct 14 2022 07:34 PM - edited Oct 17 2022 07:36 AM
@NanddeepNachan- Thanks for this code. This may get me started, but I need to check if any file was changed in the directory. If a file was modified in the library, copy that file to a library on a different web application.
Oct 17 2022 08:02 AM
Oct 17 2022 09:52 AM
Oct 17 2022 11:05 AM - edited Oct 17 2022 11:06 AM
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 <=
Oct 17 2022 11:17 AM
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 👍
Oct 19 2022 08:23 AM