{"id":2547,"date":"2013-11-18T11:59:00","date_gmt":"2013-11-18T11:59:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2013\/11\/18\/powertip-compare-the-contents-of-files-with-powershell\/"},"modified":"2013-11-18T11:59:00","modified_gmt":"2013-11-18T11:59:00","slug":"powertip-compare-the-contents-of-files-with-powershell","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/powertip-compare-the-contents-of-files-with-powershell\/","title":{"rendered":"PowerTip: Compare the Contents of Files with PowerShell"},"content":{"rendered":"<p><strong>Summary<\/strong>: Learn how to use Windows PowerShell to compare the contents of two file.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Question\">&nbsp;How can I use Windows PowerShell to compare the contents of two files?<\/p>\n<p style=\"padding-left: 30px\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Answer\">&nbsp;<\/p>\n<ul>\n<li>If the files are text files, use&nbsp;<strong>Compare-Object<\/strong>:<\/li>\n<\/ul>\n<p style=\"padding-left: 60px\">Compare-Object -ReferenceObject (Get-Content .diskcapacity.csv) -DifferenceObject <br \/>(Get-Content .diskcapacity2.csv)<\/p>\n<p style=\"padding-left: 90px\"><strong>Note<\/strong>&nbsp;&nbsp;You have to get the content of the two files and perform the comparison on the two resultant objects. If you use only the file names, you will get a comparison of the file objects rather than the content.<\/p>\n<ul>\n<li>If there are no differences between the contents of the two files, you won&rsquo;t see any output. Test what is happening by using the&nbsp;<strong>&ndash;IncludeEqual<\/strong>&nbsp;parameter:<\/li>\n<\/ul>\n<p style=\"padding-left: 60px\">Compare-Object -ReferenceObject (Get-Content .diskcapacity.csv) -DifferenceObject <br \/>(Get-Content .diskcapacity2.csv) -IncludeEqual<\/p>\n<p style=\"padding-left: 90px\">This outputs each line that matches with an equality indicator. You will get a lot of output if the files are large!&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Learn how to use Windows PowerShell to compare the contents of two file. &nbsp;How can I use Windows PowerShell to compare the contents of two files? &nbsp; If the files are text files, use&nbsp;Compare-Object: Compare-Object -ReferenceObject (Get-Content .diskcapacity.csv) -DifferenceObject (Get-Content .diskcapacity2.csv) Note&nbsp;&nbsp;You have to get the content of the two files and perform the [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[356,189,45],"class_list":["post-2547","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-powertip","tag-richard-siddaway","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Learn how to use Windows PowerShell to compare the contents of two file. &nbsp;How can I use Windows PowerShell to compare the contents of two files? &nbsp; If the files are text files, use&nbsp;Compare-Object: Compare-Object -ReferenceObject (Get-Content .diskcapacity.csv) -DifferenceObject (Get-Content .diskcapacity2.csv) Note&nbsp;&nbsp;You have to get the content of the two files and perform the [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/2547","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=2547"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/2547\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=2547"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=2547"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=2547"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}