Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

9/26/2023 PM Publish #10465

Merged
merged 6 commits into from
Sep 26, 2023
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
63 changes: 32 additions & 31 deletions reference/5.1/Microsoft.PowerShell.Core/About/about_Operators.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Describes the operators that are supported by PowerShell.
Locale: en-US
ms.date: 09/25/2023
ms.date: 09/26/2023
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-5.1&WT.mc_id=ps-gethelp
schema: 2.0.0
title: about Operators
Expand Down Expand Up @@ -114,6 +114,8 @@ expressions. For example: `(1 + 2) / 3`

However, in PowerShell, there are additional behaviors.

#### Grouping result expressions

`(...)` allows you to let output from a _command_ participate in an expression.
For example:

Expand All @@ -126,8 +128,35 @@ True
> Wrapping a command in parentheses causes the automatic variable `$?` to be
> set to `$true`, even when the enclosed command itself set `$?` to `$false`.
> For example, `(Get-Item /Nosuch); $?` unexpectedly yields **True**. For
> more information about `$?`, see
> [about_Automatic_Variables][06].
> more information about `$?`, see [about_Automatic_Variables][06].

#### Piping grouped expressions

When used as the first segment of a pipeline, wrapping a command or expression
in parentheses invariably causes _enumeration_ of the expression result. If the
parentheses wrap a _command_, it's run to completion with all output _collected
in memory_ before the results are sent through the pipeline.

For example, the outputs for these statements are different:

```powershell
PS> ConvertFrom-Json '["a", "b"]' | ForEach-Object { "The value is '$_'" }

The value is 'a b'

PS> (ConvertFrom-Json '["a", "b"]') | ForEach-Object { "The value is '$_'" }

The value is 'a'
The value is 'b'
```

Grouping an expression before piping also ensures that subsequent
object-by-object processing can't interfere with the enumeration the command
uses to produce its output.

For example, piping the output from `Get-ChildItem` to `Rename-Item` can have
unexpected effects where an item is renamed, then discovered again and renamed
a second time.

#### Grouping assignment statements

Expand Down Expand Up @@ -184,34 +213,6 @@ in the body of the `if` statement.
> between the assignment operator (`=`) and the equality-comparison operator
> (`-eq`).

#### Piping grouped expressions

When used as the first segment of a pipeline, wrapping a command or expression
in parentheses invariably causes _enumeration_ of the expression result. If the
parentheses wrap a _command_, it's run to completion with all output _collected
in memory_ before the results are sent through the pipeline.

For example, the outputs for these statements are different:

```powershell
PS> ConvertFrom-Json '["a", "b"]' | ForEach-Object { "The value is '$_'" }

The value is 'a b'

PS> (ConvertFrom-Json '["a", "b"]') | ForEach-Object { "The value is '$_'" }

The value is 'a'
The value is 'b'
```

Grouping an expression before piping also ensures that subsequent
object-by-object processing can't interfere with the enumeration the command
uses to produce its output.

For example, piping the output from `Get-ChildItem` to `Rename-Item` can have
unexpected effects where an item is renamed, then discovered again and renamed
a second time.

### Subexpression operator `$( )`

Returns the result of one or more statements. For a single result, returns a
Expand Down
74 changes: 37 additions & 37 deletions reference/5.1/Microsoft.PowerShell.Utility/Write-Host.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml
Locale: en-US
Module Name: Microsoft.PowerShell.Utility
ms.date: 12/12/2022
ms.date: 09/26/2023
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/write-host?view=powershell-5.1&WT.mc_id=ps-gethelp
schema: 2.0.0
title: Write-Host
Expand All @@ -24,10 +24,10 @@ Write-Host [[-Object] <Object>] [-NoNewline] [-Separator <Object>] [-ForegroundC
## DESCRIPTION

The `Write-Host` cmdlet's primary purpose is to produce for-(host)-display-only output, such as
printing colored text like when prompting the user for input in conjunction with [Read-Host](Read-Host.md).
`Write-Host` uses the [ToString()](/dotnet/api/system.object.tostring) method to write the
output. By contrast, to output data to the pipeline, use [Write-Output](Write-Output.md) or implicit
output.
printing colored text like when prompting the user for input in conjunction with
[Read-Host](Read-Host.md). `Write-Host` uses the [ToString()](/dotnet/api/system.object.tostring)
method to write the output. By contrast, to output data to the pipeline, use
[Write-Output](Write-Output.md) or implicit output.

You can specify the color of text by using the `ForegroundColor` parameter, and you can specify the
background color by using the `BackgroundColor` parameter. The Separator parameter lets you specify
Expand Down Expand Up @@ -122,22 +122,22 @@ thereby suppresses it. For more information, see

Specifies the background color. There is no default. The acceptable values for this parameter are:

- Black
- DarkBlue
- DarkGreen
- DarkCyan
- DarkRed
- DarkMagenta
- DarkYellow
- Gray
- DarkGray
- Blue
- Green
- Cyan
- Red
- Magenta
- Yellow
- White
- `Black`
- `DarkBlue`
- `DarkGreen`
- `DarkCyan`
- `DarkRed`
- `DarkMagenta`
- `DarkYellow`
- `Gray`
- `DarkGray`
- `Blue`
- `Green`
- `Cyan`
- `Red`
- `Magenta`
- `Yellow`
- `White`

```yaml
Type: System.ConsoleColor
Expand All @@ -156,22 +156,22 @@ Accept wildcard characters: False

Specifies the text color. There is no default. The acceptable values for this parameter are:

- Black
- DarkBlue
- DarkGreen
- DarkCyan
- DarkRed
- DarkMagenta
- DarkYellow
- Gray
- DarkGray
- Blue
- Green
- Cyan
- Red
- Magenta
- Yellow
- White
- `Black`
- `DarkBlue`
- `DarkGreen`
- `DarkCyan`
- `DarkRed`
- `DarkMagenta`
- `DarkYellow`
- `Gray`
- `DarkGray`
- `Blue`
- `Green`
- `Cyan`
- `Red`
- `Magenta`
- `Yellow`
- `White`

```yaml
Type: System.ConsoleColor
Expand Down
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: 06/30/2023
ms.date: 09/26/2023
schema: 2.0.0
title: about ANSI terminals
---
Expand Down Expand Up @@ -91,22 +91,22 @@ The following members control how or when ANSI formatting is used:
- The `$PSStyle.Background` and `$PSStyle.Foreground` members are strings that
contain the ANSI escape sequences for the 16 standard console colors.

- **Black**
- **BrightBlack**
- **White**
- **BrightWhite**
- **Red**
- **BrightRed**
- **Magenta**
- **BrightMagenta**
- **Blue**
- **BrightBlue**
- **Cyan**
- **BrightCyan**
- **Green**
- **BrightGreen**
- **Yellow**
- **BrightYellow**
- `Black`
- `BrightBlack`
- `White`
- `BrightWhite`
- `Red`
- `BrightRed`
- `Magenta`
- `BrightMagenta`
- `Blue`
- `BrightBlue`
- `Cyan`
- `BrightCyan`
- `Green`
- `BrightGreen`
- `Yellow`
- `BrightYellow`

The values are settable and can contain any number of ANSI escape sequences.
There is also a `FromRgb()` method to specify 24-bit color. There are two
Expand All @@ -118,7 +118,7 @@ The following members control how or when ANSI formatting is used:
```

Either of the following examples set the background color the 24-bit color
**Beige**.
`Beige`.

```powershell
$PSStyle.Background.FromRgb(245, 245, 220)
Expand Down
26 changes: 14 additions & 12 deletions reference/7.2/Microsoft.PowerShell.Core/About/about_Operators.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: Describes the operators that are supported by PowerShell.
Locale: en-US
ms.date: 09/25/2023
ms.date: 09/26/2023
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-7.2&WT.mc_id=ps-gethelp
schema: 2.0.0
title: about Operators
Expand Down Expand Up @@ -114,6 +114,8 @@ expressions. For example: `(1 + 2) / 3`

However, in PowerShell, there are additional behaviors.

#### Grouping result expressions

`(...)` allows you to let output from a _command_ participate in an expression.
For example:

Expand All @@ -122,6 +124,17 @@ PS> (Get-Item *.txt).Count -gt 10
True
```

#### Piping grouped expressions

When used as the first segment of a pipeline, wrapping a command or expression
in parentheses invariably causes _enumeration_ of the expression result. If the
parentheses wrap a _command_, it's run to completion with all output _collected
in memory_ before the results are sent through the pipeline.

Grouping an expression before piping also ensures that subsequent
object-by-object processing can't interfere with the enumeration the command
uses to produce its output.

#### Grouping assignment statements

Ungrouped assignment statements don't output values. When grouping an
Expand Down Expand Up @@ -177,17 +190,6 @@ in the body of the `if` statement.
> between the assignment operator (`=`) and the equality-comparison operator
> (`-eq`).

#### Piping grouped expressions

When used as the first segment of a pipeline, wrapping a command or expression
in parentheses invariably causes _enumeration_ of the expression result. If the
parentheses wrap a _command_, it's run to completion with all output _collected
in memory_ before the results are sent through the pipeline.

Grouping an expression before piping also ensures that subsequent
object-by-object processing can't interfere with the enumeration the command
uses to produce its output.

### Subexpression operator `$( )`

Returns the result of one or more statements. For a single result, returns a
Expand Down
Loading