PowerShell script to compare the contents of two folders

Need to find out if two folders have the same files in them? Here is a quick PowerShell script to make it happen!

PS C:\Windows\system32> $server1 = get-childitem -Recurse -path E:\folder1
PS C:\Windows\system32> $server2 = get-childitem -Recurse -path \\server2\folder1
PS C:\Windows\system32> Compare-Object -ReferenceObject $server1 -DifferenceObject $server2

InputObject SideIndicator
———– ————-
Sample.file.txt <=

 

References:

https://blogs.technet.com/b/heyscriptingguy/archive/2011/10/08/easily-compare-two-folders-by-using-powershell.aspx