Help with Compare CSV and Output only Mismatch

So here is my problem I am comparing two CSV with 2 column set for comparison. If first column match and second column dont output the result.

 

Her is my script.

 

$ReferenceObject = Import-Csv -Path "PSLocation\APPLIST.csv"
$DifferenceObject = Import-Csv -Path "PSLocation\software.csv'

$AppInBoth = Compare-Object -ReferenceObject $ReferenceObject.DisplayName -DifferenceObject $DifferenceObject.DisplayName -IncludeEqual |

Where-Object {$_.SideIndicator -eq "=="} |
Select-Object -ExpandProperty InputObject

$results = ForEach($File in $AppInBoth) {
$1 = $ReferenceObject | Where-Object {$_.DisplayName -Like $File}
$2 = $DifferenceObject | Where-Object {$_.DisplayName -Like $File}
New-Object -TypeName psobject -Property @{
"Apps" = $File
"Current" = $1.DisplayVersion
"Available to Update" = $2.DisplayVersion
"Package Download Location" = $1.Package

}
}

$results | Out-GridView

It looks like you are trying to join two objects. This was just discussed in a post recently. Take a look at this post:

https://powershell.org/forums/topic/combining-data-how-to-also-add-data-that-is-in-set2-and-not-set1/

[quote quote=193327]It looks like you are trying to join two objects. This was just discussed in a post recently. Take a look at this post:

Combining data – how to also add data that is in set2 and not set1?
<iframe class="wp-embedded-content" style="position: absolute; clip: rect(1px, 1px, 1px, 1px);" title="" src="https://powershell.org/forums/topic/combining-data-how-to-also-add-data-that-is-in-set2-and-not-set1/embed/#?secret=PE7qaDTwIc" width="600" height="338" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" sandbox="allow-scripts" data-secret="PE7qaDTwIc" data-mce-fragment="1"></iframe>

[/quote]
My Script does exactly what I want except I want it to only Matching from column one and mismatch from column two and display result in column 3

Explaining that you want something from, to perform matches, to determine differences, etc. on columnx and columny has no context. It is much easier for the community to assist you in parsing data if you provide an example of the data and an example of the end result, like the aforementioned post.

[quote quote=193333]Explaining that you want something from, to perform matches, to determine differences, etc. on columnx and columny has no context. It is much easier for the community to assist you in parsing data if you provide an example of the data and an example of the end result, like the aforementioned post.

[/quote]
Sorry for making it difficult here is the example.

Apps Current Version Available to Update


Adobe Acrobat Reader DC 19.021.20047 19.021.20058
Bang & Olufsen Audio 9.0.212.0 9.0.212.0

 

My script show this result listed above I would like to only App with the version mismatch.

How about just filter the $result as

[pre]
$result | where {$.“Current Version” -ne $.“Available to Update”}
[/pre]

or you test the version before creating the psobject

[pre]
if ($1.DisplayVersion -ne $2.DisplayVersion)
{
New-Object -TypeName psobject -Property @{
“Apps” = $File
“Current” = $1.DisplayVersion
“Available to Update” = $2.DisplayVersion
“Package Download Location” = $1.Package
} # psobject
} # if ($1.DisplayVersion -ne $2.DisplayVersion)
[/pre]

 

That actually works. Glad we have a community like this that look at different angles.

If you are working with versions, you should use the [version] type accelerator, otherwise you are comparing strings and just doing -ne could mean the current version is higher than where you are getting the available version. Here is an example:

$apps = @()
$apps += [pscustomobject]@{
    'Apps'                = 'Adobe Acrobat Reader DC'
    'Current Version'     = '19.021.20047'
    'Available to Update' = '19.021.20058'
}

$apps += [pscustomobject]@{
    'Apps'                = 'Bang & Olufsen Audio'
    'Current Version'     = '9.0.212.0'
    'Available to Update' = '9.0.212.0'
}



$temp = $apps | Select Apps,
                       @{Name='Current Version';Expression={[version]$_.'Current Version'}},
                       @{Name='Available to Update';Expression={[version]$_.'Available to Update'}}


$temp | Where{$_.'Current Version' -lt $_.'Available to Update'

This accelerator also allows you to check specific parts of the version if want to be specific:

PS C:\WINDOWS\system32> $temp[0].'Available to Update'.Build
20058

PS C:\WINDOWS\system32> $temp[0].'Available to Update'.Major
19

PS C:\WINDOWS\system32> $temp[0].'Available to Update'.MajorRevision
-1

PS C:\WINDOWS\system32> $temp[0].'Available to Update'.Minor
21

PS C:\WINDOWS\system32> $temp[0].'Available to Update'.MinorRevision
-1

PS C:\WINDOWS\system32> $temp[0].'Available to Update'.Revision
-1

PS C:\WINDOWS\system32> $temp[0].'Available to Update'

Major  Minor  Build  Revision
-----  -----  -----  --------
19     21     20058  -1    

That version type is a neat trick :slight_smile: You could define the type in pscustomobject and skip the temp variable

[pre]
$apps = @()
$apps += [pscustomobject]@{
‘Apps’ = ‘Adobe Acrobat Reader DC’
‘Current Version’ = [version]‘19.021.20047’
‘Available to Update’ = [version]‘19.021.20058’
}

$apps += [pscustomobject]@{
‘Apps’ = ‘Bang & Olufsen Audio’
‘Current Version’ = [version]‘9.0.212.0’
‘Available to Update’ = [version]‘9.0.212.0’
}

$apps | Where {$.‘Current Version’ -lt $.‘Available to Update’}
$apps[0].‘Current Version’[/pre]