如何比较PowerShell中一列略有不同的两个表?
我想比较两个不同目录中文件的版本信息 我可以这样做:如何比较PowerShell中一列略有不同的两个表?,powershell,compareobject,Powershell,Compareobject,我想比较两个不同目录中文件的版本信息 我可以这样做: $files1 = (Get-Item "$path1\*.dll").VersionInfo $files2 = (Get-Item "$path2\*.dll").VersionInfo compare-object $files1 $files2 但我得到的结果是: InputObject ----------- File: path1\AxInterop.ShDocVw.dll... File:
$files1 = (Get-Item "$path1\*.dll").VersionInfo
$files2 = (Get-Item "$path2\*.dll").VersionInfo
compare-object $files1 $files2
但我得到的结果是:
InputObject
-----------
File: path1\AxInterop.ShDocVw.dll...
File: path1\dom.dll...
(etc...)
File: path2\AxInterop.ShDocVw.dll...
File: path2\dom.dll...
(etc...)
$files1 = (Get-Item "$path1\*.dll").VersionInfo.ProductVersion
$files2 = (Get-Item "$path2\*.dll").VersionInfo.ProductVersion
compare-object $files1 $files2
$files1 = (Get-Item "$path1\*.dll").VersionInfo.FileVersion
$files2 = (Get-Item "$path2\*.dll").VersionInfo.FileVersion
compare-object $files1 $files2
但是如果有区别的话,我就必须去寻找区别是什么。我无法直接比较文件,因为一个文件集已签名,而另一个文件集未签名
最好的方法是什么
要澄清的是,当前的compare-object
cmdlet不符合我的需要,因为它显示的文件名不同,因为它们具有不同的路径。这与我无关
我想比较文件名相同但版本号不同的行。如果发现同一文件名的版本号存在差异,或者其中一个表中不存在文件名,则显示差异。使用cmdlet的-Property
参数比较并输出感兴趣的属性
允许对结果对象进行分组,并可用于根据组对象的每个文件名生成单个输出对象:
$files1 = (Get-Item $path1\*.dll).VersionInfo
$files2 = (Get-Item $path2\*.dll).VersionInfo
Compare-Object $files1 $files2 -Property { Split-Path -Leaf $_.FileName },
ProductVersion,
FileVersion |
Group-Object -Property ' Split-Path -Leaf $_.FileName ' |
Select-Object Name,
@{ n = 'SideIndicator'; e = { $_.Group.SideIndicator } },
@{ n = 'ProductVersion'; e = { $_.Group.ProductVersion -join ' <-> ' } },
@{ n = 'FileVersion'; e = { $_.Group.FileVersion -join ' <-> ' } }
也就是说,对于存在于两个位置但版本号不同的文件,SideIndicator
显示{=>,您应该告诉比较对象
它应该使用什么属性来比较…比较对象-引用对象$files1-差异对象$files2-属性文件名,文件版本
很高兴听到这个消息很有帮助,@Adrian;我的荣幸。