PowerShell Operators: A Comprehensive Guide to Comparison, Arithmetic, and Data Manipulation

Operators in PowerShell are the foundation of its logic and data manipulation capabilities. They include logical and comparison operators, bitwise operators, arithmetic operators, type operators, and other special operators. All operators begin with a dash followed by the operator name. Understanding these operators is essential for writing efficient scripts and managing systems effectively.

Logical and Comparison OperatorsBitwise OperatorsArithmetic OperatorsType OperatorsSpecial Operators

~2 min read · Updated Dec 21, 2025

1. Logical and Comparison Operators


  • -eq / -ne: Equal to / Not equal to.
  • -gt / -lt / -ge / -le: Greater than, Less than, Greater or equal, Less or equal.
  • -like / -notlike: Wildcard string comparison.
  • -contains / -notcontains: Checks if a collection contains an element.
  • -in / -notin: Tests if a value exists in an array.

Comparisons are case-insensitive by default, but case-sensitive versions exist (e.g., -ceq).


2. Boolean Operators


  • -and: True if all subexpressions are True.
  • -or: True if any subexpression is True.
  • -not / !: Negates the result.
  • -xor: True if only one subexpression is True.

3. Bitwise Operators


  • -band: Returns 1 if both bits are 1.
  • -bor: Returns 1 if either bit is 1.
  • -bxor: Returns 1 if only one bit is 1.

Useful for working with bitmasks, such as user account flags in directory services.


4. Arithmetic Operators


  • +: Addition or string concatenation.
  • -: Subtraction.
  • *: Multiplication (numeric or string repetition).
  • /: Division.
  • %: Modulo (remainder).
  • ++ / --: Increment / Decrement.
  • += / -= / *= / /=: Shortcut operations.

5. String and Array Operators


  • -replace: Replace substrings.
  • -split: Split strings into arrays.
  • -join: Join array elements into a string.

6. Type Operators


  • -is: Tests object type.
  • -isnot: Tests if object is not of a type.
  • -as: Converts object type.

Supports KB, MB, GB, TB, PB units for byte calculations.


7. Format Operator


The -f operator creates formatted strings with placeholders. Example:


"Today is {0:d} and Pi is {1:N}" -f (Get-Date), [math]::pi

8. Miscellaneous Operators


  • & (Call Operator): Executes a string or script block.
  • $() (Subexpression): Executes expressions inside double quotes.

Conclusion


PowerShell operators form the backbone of scripting logic and data manipulation. By mastering comparison, arithmetic, type, and special operators, administrators can build powerful, efficient scripts for system management.


Written & researched by Dr. Shahin Siami

Related Articles

Advanced PowerShell Tips and Tricks: Expert Techniques

PowerShell includes a set of concise, high‑impact features that experienced users rely on to write cleaner, faster, and more maintainable scripts. These expert‑level techniques—such as splatting, default parameter values, subexpressions, parenthetical execution, and custom formatting—don’t change what PowerShell does, but dramatically improve how efficiently you can work. This chapter highlights the most valuable “pro” tricks that streamline automation and reduce repetitive code.

Continue

PowerShell Security: Goals, Mechanisms, and Script Execution Policies

PowerShell Security: Goals, Mechanisms, and Script Execution Policies

Continue

Variables, Arrays, Hash Tables, and Scriptblocks in PowerShell

Variables are the foundation of data handling in PowerShell. They store values—numbers, strings, objects, and more—allowing scripts to reuse information without recalculating it. Building on variables, PowerShell provides richer structures such as arrays, hash tables, and scriptblocks, enabling powerful automation, data manipulation, and dynamic execution. Understanding these constructs is essential for writing clean, efficient, and scalable PowerShell scripts

Continue

PSDrives and PSProviders in PowerShell: Navigating Beyond the File System

Summary: In PowerShell, modules and snap-ins don’t just add cmdlets—they often introduce PSProviders, adapters that expose hierarchical data stores (such as the Registry, IIS, Active Directory, or SQL Server) as drive‑like structures. This allows administrators to navigate and manage diverse systems using familiar file‑system commands. Alongside providers, PSDrives represent active connections to these data stores. Together, they create a unified, intuitive way to work with complex environments using consistent PowerShell syntax.

Continue

Working with HTML and XML Data in PowerShell

PowerShell provides robust capabilities for handling structured data formats such as HTML and XML. HTML is useful for generating professional-looking reports, while XML is widely used for configuration, serialization, and data persistence. PowerShell cmdlets like Invoke-WebRequest, ConvertTo-HTML, Export-Clixml, and Select-XML make it easy to retrieve, parse, generate, and query these formats. By mastering these tools, administrators can automate reporting, preserve complex data structures, and integrate PowerShell with web and enterprise systems.

Continue

Regular Expressions in PowerShell: Patterns, Operators, and Applications

Regular expressions (Regex) are a powerful language for describing data patterns. PowerShell integrates industry-standard regex syntax through the .NET library, enabling pattern matching, searching, and replacing across text and structured data. From validating emails and IP addresses to parsing logs and file paths, regex provides flexible tools for administrators. PowerShell supports regex through operators like -match, cmdlets such as Select-String, and constructs like Switch -regex, as well as the dedicated [regex] object for advanced operations.

Continue