根据版本号和一些标准比较文件并格式化输出
Comparing files based on version number and some criterias and Formatting the output
我正在使用 Powershell 中的比较对象根据大小、上次写入时间和版本号比较 dll 文件。这些文件存储在远程服务器上。我得到了结果。唯一的问题是如何从结果中获取版本号的值。在我之前的问题中,我采用了一种未优化的不同方法,您可以在此处查看:
我更新的脚本是:
$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 :
对象属性反序列化的深度可能有限制。无论如何,这是一种可行的方法。
查看此 link 了解更多信息 link
$first=Invoke-Command -Session $s1 -ScriptBlock{param($path1) Get-ChildItem -Path $path1 -Filter *.dll | Export-Clixml -Path '\networkshare\first.xml' } -ArgumentList $path1
$second=Invoke-Command -Session $s2 -ScriptBlock{param($path2) Get-ChildItem -Path $path2 -Filter *.dll | Export-Clixml -Path '\networkshare\second.xml'} -ArgumentList $path2
$first_xml = Import-Clixml -Path '\networkshare\first.xml'
$second_xml = Import-Clixml -Path '\networkshare\second.xml'
Compare-Object -ReferenceObject $first_xml -DifferenceObject $second_xml -Property Name, Length, LastWriteTime, VersionInfo -PassThru |
Select-Object Name, Length, LastWriteTime, sideindicator,@{n='VersionInfo';e= { $_.VersionInfo.productversion }}
我正在使用 Powershell 中的比较对象根据大小、上次写入时间和版本号比较 dll 文件。这些文件存储在远程服务器上。我得到了结果。唯一的问题是如何从结果中获取版本号的值。在我之前的问题中,我采用了一种未优化的不同方法,您可以在此处查看:
$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 :
对象属性反序列化的深度可能有限制。无论如何,这是一种可行的方法。
查看此 link 了解更多信息 link
$first=Invoke-Command -Session $s1 -ScriptBlock{param($path1) Get-ChildItem -Path $path1 -Filter *.dll | Export-Clixml -Path '\networkshare\first.xml' } -ArgumentList $path1
$second=Invoke-Command -Session $s2 -ScriptBlock{param($path2) Get-ChildItem -Path $path2 -Filter *.dll | Export-Clixml -Path '\networkshare\second.xml'} -ArgumentList $path2
$first_xml = Import-Clixml -Path '\networkshare\first.xml'
$second_xml = Import-Clixml -Path '\networkshare\second.xml'
Compare-Object -ReferenceObject $first_xml -DifferenceObject $second_xml -Property Name, Length, LastWriteTime, VersionInfo -PassThru |
Select-Object Name, Length, LastWriteTime, sideindicator,@{n='VersionInfo';e= { $_.VersionInfo.productversion }}