簡體   English   中英

根據版本號和一些其他條件比較文件並格式化輸出

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

我正在使用Powershell中的Compare-object根據大小,上次寫入時間和版本號比較2個文件。 我正在得到結果。 唯一的問題是如何從結果中獲取版本號的值。

   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}

結果采用以下格式:我希望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}

替換此行:

$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 = 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