简体   繁体   English

根据版本号和一些其他条件比较文件并格式化输出

[英]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. 我正在使用Powershell中的Compare-object根据大小,上次写入时间和版本号比较2个文件。 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}" 结果采用以下格式:我希望versioninfo包含值,而不是“ @ {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 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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