根据版本号和其他一些标准比较文件并格式化输出
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}
结果采用以下格式:我希望版本信息包含值,而不是“@{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 }
我在 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}
结果采用以下格式:我希望版本信息包含值,而不是“@{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 }