I am comparing dll files based on size, last write time and version number using Compare-object in Powershell. These files are stored on remote servers. I am getting the result. The only problem is how to get the value of the version number from the result. In my previous question, I was following a different approach which was not optimized, you can view it here : Comparing files based on version number and some other criteria and Formatting the output My updated script is:
$s1=New-PSSession -ComputerName $c1
$first=Invoke-Command -Session $s1 -ScriptBlock{param($path1) Get-ChildItem -Path $path1 -Filter *.dll} -ArgumentList $path1
$s2=New-PSSession -ComputerName $c2
$second=Invoke-Command -Session $s2 -ScriptBlock{param($path2) Get-ChildItem -Path $path2 -Filter *.dll} -ArgumentList $path2
$diff = Compare-Object -ReferenceObject $first -DifferenceObject $second -Property Name, Length, LastWriteTime, VersionInfo -PassThru | Select Name, Length, LastWriteTime, sideindicator,@{n="VersionInfo";e= { $_.VersionInfo.Productversion }}
$diff
Here c1 and c2 are computer names and path1 and path2 are the paths of the folders in c1 and c2 respectively. The output does not contain version number. It is of following format:
Name : PhotoViewer.dll
Length : 20480
LastWriteTime : 8/9/2015 4:46:08 PM
SideIndicator : <=
VersionInfo :