liveBook · Manning

Comparison

As explained in Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS

A comparison is an expression that evaluates a relationship between values and produces a Boolean result.

A comparison tests the relationship between two values and returns a Boolean result: True or False. In PowerShell, comparison operators express equality, inequality, ordering, and text-pattern relationships. section 12.3

Use these PowerShell operators to test values:

  • -eq and -ne test equality and inequality; -gt, -lt, -ge, and -le test numeric or date ordering. section 12.3
  • String comparisons are case-insensitive by default; the c-prefixed operators, such as -ceq and -cgt, request case-sensitive comparisons. section 12.3
  • Combine tests with -and or -or, and reverse a Boolean value with -not. section 12.3

Filter processes by memory

Get-Process | Where-Object {$_.WorkingSet -gt 100MB} examines each process. The $_ placeholder represents the current object, WorkingSet selects its property, and only objects producing True continue through the pipeline. Verify property names with Get-Member rather than relying on displayed column headings. section 12.4

Get-Process | where WorkingSet -gt 100MB

Use the shorter Where-Object form for a single comparison: Get-Process | where WorkingSet -gt 100MB. section 12.4

How Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS covers it

How deep it goes
Explains operator categories, Boolean logic, placeholders, properties, and pipeline behavior through process-filtering examples.
Examples
Demonstrates numeric, date, string, process-response, and process-memory comparisons.
What it assumes
Assumes familiarity with PowerShell objects and pipelines while reinforcing property discovery through Get-Member.
What you can do after
Apply comparisons through Where-Object to retain pipeline objects matching numeric, property-based, or combined conditions.
How it connects
Connects comparisons with Boolean values, logical operators, object properties, pipelines, Where-Object, and Get-Member.

Also explained in

Compare how 8 books explain comparison →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS. The section links point to the parts of the book it draws on.