Forum Discussion
mwilliams71
Oct 14, 2022Brass Contributor
Comparing Files in two Document Libraries with PowerShell
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 ...
Joao Livio
Oct 14, 2022Iron Contributor
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.
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/compare-object?view=powershell-7.2
mwilliams71
Oct 14, 2022Brass Contributor
I want to automate this by using PowerShell and if any code is different in the multiple directories, PowerShell should copy what files have changed to the Library.
- Joao LivioOct 14, 2022Iron Contributor
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
- mwilliams71Oct 17, 2022Brass ContributorIf the column "Modified" is different, what result will I get? and how will I store this into a variable?
This may work for initiating the copy file PowerShell script.- Joao LivioOct 17, 2022Iron ContributorSee link in first reply, have examples