How to Compare two .txt files using PowerShell?

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

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
3 weeks, 6 days ago.

  • 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: 18
    Points: 77
    Helping Hand
    Rank: Member

    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

You must be logged in to reply to this topic.