Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# https://help.github.com/articles/about-codeowners/

* @sdwheeler @michaeltlombardi
* @sdwheeler
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Describes the operators that compare values in PowerShell.
Locale: en-US
ms.date: 01/18/2026
ms.date: 07/01/2026
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_comparison_operators?view=powershell-5.1&WT.mc_id=ps-gethelp
schema: 2.0.0
title: about_Comparison_Operators
Expand Down Expand Up @@ -60,12 +60,12 @@ case-sensitive operator. To make a comparison operator case-sensitive, add a
To make the case-insensitivity explicit, add an `i` after `-`. For example,
`-ieq` is the explicitly case-insensitive version of `-eq`.

String comparisons use the [InvariantCulture][01] for both case-sensitive and
String comparisons use the [InvariantCulture][15] for both case-sensitive and
case-insensitive comparisons. The comparisons are between unicode code points
and don't use culture-specific collation ordering. The results are the same
regardless of the current culture.

When the left-hand value in the comparison expression is a [scalar][15] value,
When the left-hand value in the comparison expression is a [scalar][03] value,
the operator returns a **Boolean** value. When the left-hand value in the
expression is a collection, the operator returns the elements of the collection
that match the right-hand value of the expression. Right-hand values are always
Expand Down Expand Up @@ -176,9 +176,9 @@ False

In this example, we created two objects with identical properties. Yet, the
equality test result is **False** because they're different objects. To create
comparable classes, you need to implement [System.IEquatable\<T>][03] in your
comparable classes, you need to implement [System.IEquatable\<T>][17] in your
class. The following example demonstrates the partial implementation of a
**MyFileInfoSet** class that implements [System.IEquatable\<T>][03] and has two
**MyFileInfoSet** class that implements [System.IEquatable\<T>][17] and has two
properties, **File** and **Size**. The `Equals()` method returns **True** if
the File and Size properties of two **MyFileInfoSet** objects are the same.

Expand Down Expand Up @@ -259,7 +259,7 @@ In the following examples, all statements return **True**.
> [!NOTE]
> In most programming languages the greater-than operator is `>`. In
> PowerShell, this character is used for redirection. For details, see
> [about_Redirection][09].
> [about_Redirection][08].

When the left-hand side is a collection, these operators compare each member of
the collection with the right-hand side. Depending on their logic, they either
Expand Down Expand Up @@ -313,7 +313,7 @@ Members smaller than or equal to 7
7
```

These operators work with any class that implements [System.IComparable][02].
These operators work with any class that implements [System.IComparable][16].

Examples:

Expand Down Expand Up @@ -372,7 +372,7 @@ used for the comparison and is obtained by casting the member to a string.
### -like and -notlike

`-like` and `-notlike` behave similarly to `-eq` and `-ne`, but the right-hand
side could be a string containing [wildcards][11].
side could be a string containing [wildcards][10].

Example:

Expand Down Expand Up @@ -421,7 +421,12 @@ False
`-match` and `-notmatch` use regular expressions to search for pattern in the
left-hand side values. Regular expressions can match complex patterns like
email addresses, UNC paths, or formatted phone numbers. The right-hand side
string must adhere to the [regular expressions][10] rules.
string must adhere to the [regular expressions][09] rules.

> [!NOTE]
> Poorly designed or maliciously crafted regular expressions can create denial
> of service conditions. For more information, see the
> [Regular expression safety][04] section of this article.

Scalar examples:

Expand Down Expand Up @@ -510,17 +515,22 @@ if ('<version>1.0.0</version>' -match '<version>(.*?)</version>') {
}
```

For details, see [about_Regular_Expressions][10] and
[about_Automatic_Variables][06].
For details, see [about_Regular_Expressions][09] and
[about_Automatic_Variables][05].

## Replacement operator

### Replacement with regular expressions

Like `-match`, the `-replace` operator uses regular expressions to find the
specified pattern. But unlike `-match`, it replaces the matches with another
specified value.

> [!NOTE]
> Poorly designed or maliciously crafted regular expressions can create denial
> of service conditions. For more information, see the
> [Regular expression safety][04] section of this article.

### Replacement with regular expressions

Syntax:

```
Expand Down Expand Up @@ -605,8 +615,8 @@ include a literal `$` in the resulting replacement. For example:
'5.72' -replace '(.+)', '$$1' # Output: $1
```

To learn more, see [about_Regular_Expressions][10] and
[Substitutions in Regular Expressions][05].
To learn more, see [about_Regular_Expressions][09] and
[Substitutions in Regular Expressions][02].

### Substituting in a collection

Expand Down Expand Up @@ -754,30 +764,79 @@ $b -isnot [int] # Output: True
$a -isnot $b.GetType() # Output: True
```

## Regular expression safety

The number of comparison operations required to match a regular expression
pattern can increase exponentially if the pattern includes a large number of
alternation constructs, espcecially when it includes nested optional
quantifiers. For example, the regular expression pattern `^(a+)+$` is designed
to match a complete string that contains one or more "a" characters. The
regular expression engine must use the regular expression to follow all
possible paths through the data before it can conclude that the match is
unsuccessful, and the nested parentheses create many additional paths through
the data.

> [!WARNING]
> A malicious user can provide input to regular expressions causing a
> [Denial-of-Service attack][11], also known as a ReDoS attack.

To defend against ReDoS scenarios, create `[regex]` objects that specify a
timeout. The regex engine terminates the search for a match when it exceeds the
time limit. For example, the following code creates a regex object with a
2-second timeout:

```powershell
$pattern = '^(a+)+$'
$regexOptions = 'None'
$matchTimeout = [timespan]::FromSeconds(2)
$regex = [regex]::new($pattern, $regexOptions, $matchTimeout)
$regex.IsMatch('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaX')
```

After 2 seconds, the regex engine terminates the search and returns the
following error:

```Output
MethodInvocationException: Exception calling "IsMatch" with "1" argument(s):
"The Regex engine has timed out while trying to match a pattern to an input
string. This can occur for many reasons, including very large inputs or
excessive backtracking caused by nested quantifiers, back-references and other
factors."
```

For more information about the `[regex]` class and regex performance, see the
following articles:

- [System.Text.RegularExpressions.Regex][19]
- [Backtracking in .NET regular expressions][01]

## See also

- [about_Booleans][07]
- [about_Operators][08]
- [about_Regular_Expressions][10]
- [about_Wildcards][11]
- [about_Booleans][06]
- [about_Operators][07]
- [about_Regular_Expressions][09]
- [about_Wildcards][10]
- [Compare-Object][14]
- [ForEach-Object][12]
- [Where-Object][13]

<!-- link references -->
[01]: /dotnet/api/system.globalization.cultureinfo.invariantculture
[02]: /dotnet/api/system.icomparable
[03]: /dotnet/api/system.iequatable-1
[04]: /dotnet/api/system.text.regularexpressions.match
[05]: /dotnet/standard/base-types/substitutions-in-regular-expressions
[06]: about_Automatic_Variables.md
[07]: about_Booleans.md
[08]: about_Operators.md
[09]: about_Redirection.md#potential-confusion-with-comparison-operators
[10]: about_Regular_Expressions.md
[11]: about_Wildcards.md
[01]: /dotnet/standard/base-types/backtracking-in-regular-expressions
[02]: /dotnet/standard/base-types/substitutions-in-regular-expressions
[03]: /powershell/scripting/learn/glossary#scalar-value
[04]: #regular-expression-safety
[05]: about_Automatic_Variables.md
[06]: about_Booleans.md
[07]: about_Operators.md
[08]: about_Redirection.md#potential-confusion-with-comparison-operators
[09]: about_Regular_Expressions.md
[10]: about_Wildcards.md
[11]: https://www.cisa.gov/news-events/news/understanding-denial-service-attacks
[12]: xref:Microsoft.PowerShell.Core.ForEach-Object
[13]: xref:Microsoft.PowerShell.Core.Where-Object
[14]: xref:Microsoft.PowerShell.Utility.Compare-Object
[15]: /powershell/scripting/learn/glossary#scalar-value

[15]: xref:System.Globalization.CultureInfo.InvariantCulture%2A
[16]: xref:System.IComparable
[17]: xref:System.IEquatable%601
[18]: xref:System.Text.RegularExpressions.Match
[19]: xref:System.Text.RegularExpressions.Regex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Describes the types of errors in PowerShell and the mechanisms for handling them.
Locale: en-US
ms.date: 06/02/2026
ms.date: 07/02/2026
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_error_handling?view=powershell-5.1&WT.mc_id=ps-gethelp
schema: 2.0.0
title: about_Error_Handling
Expand Down Expand Up @@ -254,19 +254,19 @@ The scope of the escalated error depends on context:
& {
param()
$ErrorActionPreference = 'Stop'
Get-Item 'NoSuchPath'
1/0 # Divide by zero error
} 2>$null
'after'
```

- ADVANCED: script-terminating ('after' does NOT print)
- ADVANCED: statement-terminating ('after' DOES print)

```powershell
& {
[CmdletBinding()]
param()
$ErrorActionPreference = 'Stop'
Get-Item 'NoSuchPath'
1/0 # Divide by zero error
} 2>$null
'after'
```
Expand Down
24 changes: 18 additions & 6 deletions reference/5.1/Microsoft.PowerShell.Core/About/about_Split.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Explains how to use the Split operator to split one or more strings into substrings.
Locale: en-US
ms.date: 01/18/2026
ms.date: 07/01/2026
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_split?view=powershell-5.1&WT.mc_id=ps-gethelp
schema: 2.0.0
title: about_Split
Expand All @@ -28,9 +28,14 @@ change the following elements of the Split operation:
- Options that specify the conditions under which the delimiter is matched,
such as SimpleMatch and Multiline.

> [!NOTE]
> Poorly designed or maliciously crafted regular expressions can create denial
> of service conditions. For more information, see the
> _Regular expression safety_ section of [about_Comparison_Operators][01].

## Syntax

The following diagram shows the syntax for the -split operator.
The following diagram shows the syntax for the `-split` operator.

The parameter names do not appear in the command. Include only the parameter
values. The values must appear in the order specified in the syntax diagram.
Expand Down Expand Up @@ -506,7 +511,14 @@ LastName, FirstName

## See also

- [Split-Path](xref:Microsoft.PowerShell.Management.Split-Path)
- [about_Operators](about_Operators.md)
- [about_Comparison_Operators](about_Comparison_Operators.md)
- [about_Join](about_Join.md)
- [Split-Path][05]
- [about_Operators][04]
- [about_Comparison_Operators][02]
- [about_Join][03]

<!-- link references -->
[01]: about_Comparison_Operators.md#regular-expression-safety
[02]: about_Comparison_Operators.md
[03]: about_Join.md
[04]: about_Operators.md
[05]: xref:Microsoft.PowerShell.Management.Split-Path
28 changes: 17 additions & 11 deletions reference/5.1/Microsoft.PowerShell.Core/About/about_Switch.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Explains how to use a switch to handle multiple `if` statements.
Locale: en-US
ms.date: 01/18/2026
ms.date: 07/01/2026
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_switch?view=powershell-5.1&WT.mc_id=ps-gethelp
schema: 2.0.0
title: about_Switch
Expand Down Expand Up @@ -47,7 +47,7 @@ if ("$(<result2-to-be-matched>)") -eq ("$(<test-expression>)") {<action>}
Expressions include literal values (strings or numbers), variables, and
scriptblocks that return a boolean value. The `switch` statement converts all
values to strings before comparison. For an example, see
[Impact of string conversion][02] later in this article.
[Impact of string conversion][01] later in this article.

The `<test-expression>` is evaluated in expression mode. If the expression
returns more than one value, such as an array or other enumerable type, the
Expand Down Expand Up @@ -110,7 +110,7 @@ conditions. It's equivalent to an `else` clause in an `if` statement. Only one
default, the comparison is case-insensitive. The **File** parameter only
supports one file. If multiple **File** parameters are included, only the
last one is used. For more information see the
[**File** parameter examples][01].
[**File** parameter examples][02].
- **Regex** - Performs regular expression matching of the value to the
condition. If the match clause isn't a string, this parameter is ignored.
The comparison is case-insensitive. The `$Matches` automatic variable is
Expand Down Expand Up @@ -392,6 +392,11 @@ switch ((Get-Date 1-Jan-2022), (Get-Date 25-Dec-2021)) {
}
```

> [!NOTE]
> Poorly designed or maliciously crafted regular expressions can create denial
> of service conditions. For more information, see the _Regular expression
> safety_ section of [about_Comparison_Operators][05].

### Read the content of a file with `switch`

Using the `switch` statement with the **File** parameter is an efficient way to
Expand Down Expand Up @@ -443,15 +448,16 @@ switch -File $fileEscaped { foo { 'Foo' } }
## See also

- [about_Break][04]
- [about_Continue][05]
- [about_If][06]
- [about_Script_Blocks][07]
- [about_Continue][06]
- [about_If][07]
- [about_Script_Blocks][08]

<!-- link references -->
[01]: #read-the-content-of-a-file-with-switch
[02]: #impact-of-string-conversion
[01]: #impact-of-string-conversion
[02]: #read-the-content-of-a-file-with-switch
[03]: about_Automatic_Variables.md
[04]: about_break.md
[05]: about_Continue.md
[06]: about_If.md
[07]: about_Script_Blocks.md
[05]: about_Comparison_Operators.md#regular-expression-safety
[06]: about_Continue.md
[07]: about_If.md
[08]: about_Script_Blocks.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Describes the features of PowerShell that use ANSI escape sequences and the terminal hosts that support them.
Locale: en-US
ms.date: 12/09/2025
ms.date: 07/02/2026
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_ansi_terminals?view=powershell-7.4&WT.mc_id=ps-gethelp
schema: 2.0.0
title: about_ANSI_Terminals
Expand Down Expand Up @@ -89,7 +89,9 @@ The following members control how or when ANSI formatting is used:
- `PlainText`: ANSI escape sequences are always stripped so that it's only
plain text. In remote sessions, if the remote host is set to `PlainText`,
the output is stripped of ANSI escape sequences before sending it back to
the local client.
the local client. This mode removes text formatting and rendering
sequences. It's not intended to be a comprehensive terminal-control
sanitization mechanism.
- `Host`: This is the default behavior. The ANSI escape sequences are removed
from redirected or piped output. For more information, see
[Redirecting output][02].
Expand Down
Loading