How to Compare two .txt files using PowerShell?

Welcome Forums General PowerShell Q&A How to Compare two .txt files using PowerShell?

Viewing 2 reply threads
  • Author
    Posts
    • #178962
      Participant
      Topics: 4
      Replies: 5
      Points: 57
      Rank: Member

      Good day everyone,

      I would like to ask you, how it is possible to compare two .txt files using PowerShell?
      I had generate a .txt file before and after some Fix (deploy new version)
      And now I would like to verify if the two .txt files are exactly the same or there are some differences.
      Many thanks in advance,

      my code is here:

      
      $dbAddress = "SEH05VVM745"
      $CleanDbScriptPath = "D:\AUTOMATION\Scripts\CleanDB.txt"
      
      $CleanDB = "D:\AUTOMATION\Results\CleanedDBTables.txt"
      
      $TablesDbScriptPath = "D:\AUTOMATION\Scripts\TablesDB.txt"
      
      $ImportedFiles = "D:\AUTOMATION\Results\ImportedTables.txt"
      
      #Extract DB tables (sort by table name)
      Invoke-Sqlcmd -ServerInstance $dbAddress -InputFile $TablesDbScriptPath | Out-File -FilePath $ImportedFiles
      Write-Host "DB Tables has been copied to a .txt file" -ForegroundColor Green
      
      
      
      
    • #178968
      Participant
      Topics: 0
      Replies: 28
      Points: 142
      Helping Hand
      Rank: Participant

      Try Compare-Object command

      Compare-Object (Get-Content $TablesDbScriptPath) –DifferenceObject (Get-Content $ImportedFiles)
      
    • #179040
      Participant
      Topics: 4
      Replies: 5
      Points: 57
      Rank: Member

      Hi @rejikodiyil

      Ohhh, I see, I will try.

      Many thanks 🙂

      Have a nice day

Viewing 2 reply threads
  • The topic ‘How to Compare two .txt files using PowerShell?’ is closed to new replies.