Help with Compare CSV and Output only Mismatch

Welcome Forums General PowerShell Q&A Help with Compare CSV and Output only Mismatch

Viewing 8 reply threads
  • Author
    Posts
    • #193321
      Participant
      Topics: 4
      Replies: 7
      Points: 36
      Rank: Member

      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
    • #193327
      Participant
      Topics: 10
      Replies: 1381
      Points: 1,509
      Helping Hand
      Rank: Community Hero

      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?

    • #193330
      Participant
      Topics: 4
      Replies: 7
      Points: 36
      Rank: Member

      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?

      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

    • #193333
      Participant
      Topics: 10
      Replies: 1381
      Points: 1,509
      Helping Hand
      Rank: Community Hero

      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.

    • #193339
      Participant
      Topics: 4
      Replies: 7
      Points: 36
      Rank: Member

      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.

      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.

    • #193397
      Participant
      Topics: 5
      Replies: 105
      Points: 262
      Helping Hand
      Rank: Contributor

      How about just filter the $result as

      $result | where {$_."Current Version" -ne $_."Available to Update"}
      

      or you test the version before creating the psobject

      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)
      
    • #193658
      Participant
      Topics: 4
      Replies: 7
      Points: 36
      Rank: Member

       

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

    • #193703
      Participant
      Topics: 10
      Replies: 1381
      Points: 1,509
      Helping Hand
      Rank: Community Hero

      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    
      
    • #193715
      Participant
      Topics: 5
      Replies: 105
      Points: 262
      Helping Hand
      Rank: Contributor

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

      $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'
Viewing 8 reply threads
  • You must be logged in to reply to this topic.