0

I'm trying to run reports of software our users will get on new computers. I have one list "Reference Software", which is all the software they currently have installed. Then another list, "Difference Software", which is all the software in our company that we have to manually install. I'm trying to compare these two lists and output what items are in both lists. Looking this up for weeks now, I've taken what others have suggested and try to make it work, but nothing yet.

Has anyone done something similar and got it to work???

    $ComputerName = get-content c:\temp\ComputerList.txt


Get-InstalledSoftware $ComputerName | Out-File -FilePath C:\Temp\DifferenceSoftware.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"
2
  • 2
    I'm assuming you've actually used Get-InstalledSoftware $ComputerName | Export-Csv ... instead of Get-InstalledSoftware $ComputerName | Out-File ... right? Commented Sep 6, 2022 at 20:27
  • 4
    As a recommendation, it would help if you add an example of how the reference and difference CSVs looks like and how you expect your desired output to look Commented Sep 6, 2022 at 21:14

1 Answer 1

0

Take a look at this: https://adamtheautomator.com/powershell-compare-arrays/

I hope it can help.

$ComputerName = get-content c:\temp\ComputerList.txt

Get-InstalledSoftware $ComputerName | Out-File -FilePath C:\Temp\DifferenceSoftware.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"
Sign up to request clarification or add additional context in comments.

1 Comment

Which part of the linked article are you directing the author's attention to? You should quote the relevant part(s) here in case the link breaks or changes. Otherwise, it's better to rely on testing than hope when writing an answer. What you're attempting here with the -in operator is much the same as the nested foreach loops in the question and I would expect to fail for the same reason: objects representing CSV rows that happen to have the same values but are, ultimately, different instances won't be considered equal.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.