# How to Compare two .txt files using PowerShell?

**URL:** <https://forums.powershell.org/t/how-to-compare-two-txt-files-using-powershell/13179>\
**Category:** PowerShell Help\
**Created:** [September 23, 2019, 4:29am UTC](https://forums.powershell.org/t/how-to-compare-two-txt-files-using-powershell/13179 "2019-09-23T04:29:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![alejandro01gtcz](https://avatars.discourse-cdn.com/v4/letter/a/e0b2c6/32.png) [@alejandro01gtcz](https://forums.powershell.org/u/alejandro01gtcz)\
**Post date:** [September 23, 2019, 4:29am UTC](https://forums.powershell.org/t/how-to-compare-two-txt-files-using-powershell/13179/1 "2019-09-23T04:29:22Z")

</div>

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:

[pre]

`$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`

``

[/pre]

---

<div class="post-metadata">

**Author:** ![rejikodiyil](https://avatars.discourse-cdn.com/v4/letter/r/ba8739/32.png) [@rejikodiyil](https://forums.powershell.org/u/rejikodiyil)\
**Post date:** [September 23, 2019, 5:32am UTC](https://forums.powershell.org/t/how-to-compare-two-txt-files-using-powershell/13179/2 "2019-09-23T05:32:56Z")

</div>

Try Compare-Object command  
[PRE]  
Compare-Object (Get-Content $TablesDbScriptPath) --DifferenceObject (Get-Content $ImportedFiles)  
[/PRE]

---

<div class="post-metadata">

**Author:** ![alejandro01gtcz](https://avatars.discourse-cdn.com/v4/letter/a/e0b2c6/32.png) [@alejandro01gtcz](https://forums.powershell.org/u/alejandro01gtcz)\
**Post date:** [September 23, 2019, 8:54am UTC](https://forums.powershell.org/t/how-to-compare-two-txt-files-using-powershell/13179/3 "2019-09-23T08:54:12Z")

</div>

Hi @[rejikodiyil](https://powershell.org/profile/rejikodiyil/)

Ohhh, I see, I will try.

Many thanks 🙂

Have a nice day

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:32pm UTC](https://forums.powershell.org/t/how-to-compare-two-txt-files-using-powershell/13179/4 "2024-05-16T20:32:05Z")

</div>


