简体   繁体   中英

Comparing files based on version number and some other criteria and Formatting the output

I am comparing 2 files based on size, last write time and version number using Compare-object in Powershell. I am getting the results. The only problem is how to get the value of the version number from the result.

   function dll_compare(){
   param($path1,$path2) 
   $first = Get-ChildItem -Path $path1 -Filter *.dll
   $second =  Get-ChildItem -Path $path2 -Filter *.dll
   $diff = Compare-Object -ReferenceObject $first -DifferenceObject $second -Property Name, Length, LastWriteTime, VersionInfo -PassThru  | Select Name, Length, LastWriteTime, sideindicator,@{n="path";e={$_.fullname}},@{n="VersionInfo";e={$_|Select-Object -ExpandProperty VersionInfo |Select-Object -Property Productversion}}
   $diff}

The result is in the following format: I want the versioninfo to contain the value, instead of "@{ProductVersion=10.0.10240.16384}"

Name          : PhotoViewer.dll    
Length        : 1827328    
LastWriteTime : 7/10/2015 4:31:20 PM    
SideIndicator : <=    
path          : D:\Site1\Dlls\PhotoViewer.dll    
VersionInfo   : @{ProductVersion=10.0.10240.16384}

Replace this line:

$diff = Compare-Object -ReferenceObject $first -DifferenceObject $second -Property Name, Length, LastWriteTime, VersionInfo -PassThru  | Select Name, Length, LastWriteTime, sideindicator,@{n="path";e={$_.fullname}},@{n="VersionInfo";e={$_|Select-Object -ExpandProperty VersionInfo |Select-Object -Property Productversion}

with

$diff = Compare-Object -ReferenceObject $first -DifferenceObject $second -Property Name, Length, LastWriteTime, VersionInfo -PassThru |
    Select Name, Length, LastWriteTime, sideindicator,@{n = "path"; e ={ $_.fullname }}, @{n = "VersionInfo"; e = { $_.VersionInfo.Productversion }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM