Compare
Compare-Object
3 Important Parameters:
-ReferenceObject The ReferenceObject is the baseline.
-DifferenceObject The DifferenceObject is what you are looking for differences in.
-Property This is the property of the object that you are comparing. Can be a comma-seperated list?
<= Indicates that the property is present only on the ReferenceObject (Left Side).
=> Indicates that the property is present only on the DifferenceObject (Right Side).
Compares two files and displays the differences using the File Compare command in CMD.
fc C:\path\to\file1.txt C:\path\to\file2.txtCompares the contents of two files or sets of files byte-by-byte, using the Comp command.
comp C:\path\to\file1.txt C:\path\to\file2.txtCompares two files and shows differences using PowerShell. This command reads each file's content and then compares the objects.
Compare-Object (Get-Content C:\path\to\file1.txt) (Get-Content C:\path\to\file2.txt)Checks if two files are identical, returning True or False, using PowerShell.
(Get-Content C:\path\to\file1.txt) -eq (Get-Content C:\path\to\file2.txt)An alias in PowerShell for Compare-Object, used to compare file contents similar to the Unix/Linux diff command.
Note: diff as an alias may not be available in all PowerShell environments by default.
diff (Get-Content C:\path\to\file1.txt) (Get-Content C:\path\to\file2.txt)Example: Comparing two text Files
Example: Comparing the Process List of two computers:
Collect the baseline computer's process list:
Move it to the other computer to compare:
Last updated
Was this helpful?