我正在使用 Powershell 中的比较对象根据大小、上次写入时间和版本号比较 dll 文件。这些文件存储在远程服务器上。我得到了结果。唯一的问题是如何从结果中获取版本号的值。在我之前的问题中,我采用了一种未优化的不同方法,您可以在此处查看:Comparing files based on version number and some other criteria and Formatting the output 我更新的脚本是:
$s1=New-PSSession -ComputerName $c1
$first=Invoke-Command -Session $s1 -ScriptBlock{param($path1) Get-ChildItem -Path $path1 -Filter *.dll} -ArgumentList $path1
$s2=New-PSSession -ComputerName $c2
$second=Invoke-Command -Session $s2 -ScriptBlock{param($path2) Get-ChildItem -Path $path2 -Filter *.dll} -ArgumentList $path2
$diff = Compare-Object -ReferenceObject $first -DifferenceObject $second -Property Name, Length, LastWriteTime, VersionInfo -PassThru | Select Name, Length, LastWriteTime, sideindicator,@{n="VersionInfo";e= { $_.VersionInfo.Productversion }}
$diff
这里 c1 和 c2 是计算机名,path1 和 path2 分别是 c1 和 c2 中文件夹的路径。输出不包含版本号。它的格式如下:
Name : PhotoViewer.dll
Length : 20480
LastWriteTime : 8/9/2015 4:46:08 PM
SideIndicator : <=
VersionInfo :