比较Powershell中的两个列表并输出相似之处



我正在尝试运行我们的用户将在新计算机上获得的软件的报告。我有一个清单";参考软件";,这是他们目前安装的所有软件。然后是另一个列表;差分软件";,这是我们公司所有必须手动安装的软件。我试图比较这两个列表,并输出两个列表中的项目。几周来,我一直在考虑其他人的建议,并试图让它发挥作用,但什么都没有。

有人做过类似的事情并使其发挥作用吗???

$ComputerName = get-content c:tempComputerList.txt

Get-InstalledSoftware $ComputerName | Out-File -FilePath C:TempDifferenceSoftware.csv

$Path = "C:Temp"
$DifferenceSoftware = Import-Csv -Path "$($path)DifferenceSoftware.csv"
$ReferenceSoftware = Import-Csv -Path "$($path)ReferenceSoftware.csv"

$combine = @()
foreach ($first in $DifferenceSoftware) {
foreach ($second in $ReferenceSoftware) {
if ($second -eq $first) {
$match = New-Object PSObject
$match | Add-Member Noteproperty $first
$combine += $match
}
}
}
$combine | Export-Csv -Path "$($path)combined.csv"

看看这个:https://adamtheautomator.com/powershell-compare-arrays/

我希望它能有所帮助。

$ComputerName = get-content c:tempComputerList.txt
Get-InstalledSoftware $ComputerName | Out-File -FilePath C:TempDifferenceSoftware.csv

$Path = "C:Temp"
$DifferenceSoftware = Import-Csv -Path "$($path)DifferenceSoftware.csv"
$ReferenceSoftware = Import-Csv -Path "$($path)ReferenceSoftware.csv"

#i hope this works for u as well -- Where-Object returns all items contained in both arrays
$combine = ($ReferenceSoftware | Where-Object {$_ -in $DifferenceSoftware})
$combine | Export-Csv -Path "$($path)combined.csv"

最新更新