You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `Compare-Object` cmdlet compares two sets of objects.
27
-
One set of objects is the "reference set," and the other set is the "difference set."
28
+
The `Compare-Object` cmdlet compares two sets of objects. One set of objects is the **reference**,
29
+
and the other set of objects is the **difference**.
28
30
29
-
The result of the comparison indicates whether a property value appeared only in the object from the reference set (indicated by the \<= symbol), only in the object from the difference set (indicated by the `=>` symbol) or, if the `IncludeEqual` parameter is specified, in both objects (indicated by the `==` symbol).
31
+
The result of the comparison indicates whether a property value appeared only in the **reference**
32
+
object (`<=`) or only in the **difference** object (`=>`). If the **IncludeEqual** parameter is
33
+
used, (`==`) indicates the value is in both objects.
30
34
31
-
If the reference set or the difference set is null ($null), this cmdlet generates a terminating error.
35
+
If the **reference** or the **difference** objects are null (`$null`), `Compare-Object` generates a
36
+
terminating error.
37
+
38
+
Some examples use splatting to reduce the line length of the code samples. For more information, see
39
+
[about_Splatting](../Microsoft.PowerShell.Core/About/about_Splatting.md). And, the examples use two
40
+
text files, with each value on a separate line. `Textfile1.txt` contains the values: dog, squirrel,
41
+
and bird. `Textfile1.txt` contains the values: cat, bird, and racoon.
32
42
33
43
## EXAMPLES
34
44
35
45
### Example 1: Compare the content of two text files
36
46
47
+
This example compares the contents of two text files. The output displays only the lines that are
48
+
different between the files. `Textfile1.txt` is the **reference** object (`<=`) and
49
+
`Textfile2.txt`is the **difference** object (`=>`).
50
+
51
+
Lines with content that appear in both files aren't displayed.
This command compares each line of content in two text files.
51
-
It displays all lines of content from both files, indicating whether each line appears in only Textfile1.txt or Textfile2.txt or whether each line appears in both files.
114
+
### Example 4: Compare two sets of process objects
52
115
53
-
### Example 3: Compare two sets of process objects
116
+
This example compares two sets of objects that contain the computer's running processes.
When you use the **PassThru** parameter, `Compare-Object` omits the `PSCustomObject` wrapper around the compared objects and returns the differing objects, unchanged.
236
+
When you use the **PassThru** parameter, `Compare-Object` omits the **PSCustomObject** wrapper
237
+
around the compared objects and returns the differing objects, unchanged.
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).
304
+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable,
-WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).
232
307
233
308
## INPUTS
234
309
235
310
### System.Management.Automation.PSObject
236
311
237
-
You can pipe a **DifferenceObject** object to this cmdlet.
312
+
You can send an object down the pipeline to the **DifferenceObject** parameter.
238
313
239
314
## OUTPUTS
240
315
241
316
### None
242
317
243
-
If the objects are the same, nothing is returned.
318
+
If the **reference** object and the **difference** object are the same, there's no output.
244
319
245
320
### System.Management.Automation.PSCustomObject
246
321
247
-
If the objects are different, `Compare-Object` wraps the differing objects in a `PSCustomObject` wrapper with a **SideIndicator** property to reference the differences. When you use the **PassThru** parameter, `Compare-Object` omits the `PSCustomObject` wrapper around the compared objects and returns the differing objects, unchanged.
322
+
If the objects are different, `Compare-Object` wraps the differing objects in a `PSCustomObject`
323
+
wrapper with a **SideIndicator** property to reference the differences. When you use the
324
+
**PassThru** parameter, `Compare-Object` omits the `PSCustomObject` wrapper around the compared
325
+
objects and returns the differing objects, unchanged.
248
326
249
327
## NOTES
250
328
@@ -267,4 +345,3 @@ If the objects are different, `Compare-Object` wraps the differing objects in a
0 commit comments