I am very new to PowerShell scripting.
I have two folders with hundreds of files with the same name in both folders. I am writing a long script to compare all the files and send output to a text file. When I use this script:
compare-object (get-content "D:\Folder1\file1.js") (get-content "D:\Folder2\file1.js")
compare-object (get-content "D:\Folder1\file2.js") (get-content "D:\Folder2\file2.js")
compare-object (get-content "D:\Folder1\file3.js") (get-content "D:\Folder2\file3.js")
All I get is this:
InputObject SideIndicator
----------- -------------
* New Text =>
* <=
This doesn't tell me which file has this difference. I want it to display the file name also (anyone, first or second file name).
How can I achieve that?
I know I should be using Get-Children, but I need to learn the simple thing first which can be implemented in a loop.
========= Solution Posted As a Separate Answer ================
With kind help of participants I have managed to create the following script that might be helpful for others:
Basically I have two folders.
SourceandComparewith. I am picking up each file from theSourcefolder as$f1, creating a similar file name$f2while replacingSourcewithComparewithbut keeping same file name, and then comparing both. I am using echo to print the name before each compare-object and also testing if the file exists in theComparewithfolder.Any improvement suggestion are welcome.