比较基于版本号和其他条件的文件,并格式化输出 [英] Comparing files based on version number and some other criteria and Formatting the output

查看:199
本文介绍了比较基于版本号和其他条件的文件,并格式化输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Powershell中使用比较对象,根据大小,上次写入时间和版本号比较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名称,长度,LastWriteTime,VersionInfo -PassThru |选择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}

 名称:PhotoViewer.dll 
长度:1827328
LastWriteTime:7/10/2015 4:31:20 PM
SideIndicator:< =
路径:D:\Site1\Dlls\PhotoViewer .dll
VersionInfo:@ {ProductVersion = 10.0.10240.16384}


解决方案

替换此行:

  $ diff = Compare-Object -ReferenceObject $ first -DifferenceObject $ second -Property名称,Length,LastWriteTime,VersionInfo -PassThru |选择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名称,长度,LastWriteTime,VersionInfo -PassThru | 
选择Name,Length,LastWriteTime,sideindicator,@ {n =path; e = {$ _。fullname}},@ {n =VersionInfo; e = {$ _。VersionInfo.Productversion}


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 }

这篇关于比较基于版本号和其他条件的文件,并格式化输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆