I'm working on a script that compares the content of two directories with files of the same name and returns files that are different. The property I'm using to determine if the files are different are LastWriteTime and Size.
Here is my current script:
$var1 = Get-ChildItem -path C:\proj\BIN\ -Recurse
$var2 = Get-ChildItem -path C:\proj2\BIN\ -Recurse
Compare-Object -ReferenceObject $var1 -DifferenceObject $var2 -Property Name, LastWriteTime, Size | Sort-Object Name
Here is my current output:
Name LastWriteTime Size SideIndicator
---- ------------- ---- -------------
folder1 6/1/2018 3:20:37 PM =>
folder1 5/21/2018 12:08:36 PM <=
folder2 6/1/2018 3:20:37 PM =>
folder2 5/21/2018 12:08:36 PM <=
CustomReports 6/1/2018 3:20:37 PM =>
CustomReports 5/21/2018 12:08:39 PM <=
folder3 6/1/2018 3:20:38 PM =>
folder3 5/21/2018 12:08:38 PM <=
blank.XML 6/1/2018 3:37:49 PM =>
blank.XML 11/22/2017 12:36:04 PM <=
As far as I know, the reason size is empty is because they are the same size (which they are). If this is true, no problem. If it happens to be just a coincidence, then I will need to correct it.
EDIT: size is incorrect. length is the correct property.
I want to change the output from just Name to the Fullname. If I change my it in my script it will list every file because they are in different directories.
I have added this pipe to the last line to this instead:
| Format-Table -property FullName, LastWriteTime, Size
From my understanding it the script should compare-object based off name, lastWriteTime, size and from those results sort-object by name and then return the fullname, lastWriteTime, size from those results.
My new output is:
FullName LastWriteTime Size
-------- ------------- ----
6/1/2018 3:20:37 PM
5/21/2018 12:08:36 PM
6/1/2018 3:20:37 PM
5/21/2018 12:08:36 PM
6/1/2018 3:20:37 PM
5/21/2018 12:08:39 PM
6/1/2018 3:20:38 PM
[System.IO.FileInfo]instances don't have a.Sizeproperty, only a.Lengthproperty;[System.IO.DirectoryInfo]instances (directories aka folders) have neither.Get-Memberto inspect its members (properties and methods).