![]() ![]() I invite you to follow me on Twitter and Facebook. Troubleshooting Week will continue tomorrow when I will talk about more cool stuff. ![]() ![]() JW, that is all there is to using Windows PowerShell to compare two files. Your original script reads in the complete file, and then compares it line-by-line, so it is much less efficient. Plus this operation simply obtains the file hashes, and compares the two hashes. In addition, the Get-FileHash code is rather efficient because Windows PowerShell is pretty fast when it comes to getting the file hash. PS C:\> (Get-FileHash $fileA).hash -ne (Get-FileHash $fileB).hash PS C:\> (Get-FileHash $fileA).hash -ne (Get-FileHash $fileC).hash In the following, I execute only the Get-FileHash portion of the script: Now, when I look at the portion of the code that executes, I can see that I am dealing with a Boolean, instead of trying to evaluate whether output (which is basically ignored) appears or not (as in your previous script). If((Get-FileHash $fileA).hash -ne (Get-FileHash $fileC).hash) So a better way to do this is to use Get-FileHash and compare the HASH property. Although this works, it can be a bit slow, and on more complex files, I would think it would also be a bit unreliable. This triggers the ELSE portion of the code. PS C:\> Compare-Object -ReferenceObject $(Get-Content $fileA) -DifferenceObject $(Get-Content $fileB) PS C:\> Compare-Object -ReferenceObject $(Get-Content $fileA) -DifferenceObject $(Get-Content $fileC)Īnd when I compare FileA with FileB, the following appears: To do this, I highlight the Compare-Object statement and press F-8 to execute only that portion of the code. I can use the Windows PowerShell ISE to run a portion of the code and look at it. What is really going on when using Compare-Object ? When I change it to use FileC, the script also works: When I run the script and compare FileA with FileB, the script returns the correct response: If(Compare-Object -ReferenceObject $(Get-Content $fileA) -DifferenceObject $(Get-Content $fileB)) I looked at the script you supplied, where you use Compare-Object to compare two files. Microsoft Scripting Guy, Ed Wilson, is here. I am wondering what I can do to speed things up a bit. Hey, Scripting Guy! I have a script that I wrote to compare two files, but it seems really slow. Summary : Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to compare two files. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |