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
28 changes: 24 additions & 4 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: 09/26/2023
ms.date: 04/01/2026
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 Down Expand Up @@ -35,7 +35,7 @@ a string to use to separate displayed objects. The particular result depends on
hosting PowerShell.

> [!NOTE]
> Starting in Windows PowerShell 5.0, `Write-Host` is a wrapper for `Write-Information` This allows
> Starting in Windows PowerShell 5.0, `Write-Host` is a wrapper for `Write-Information`. This allows
> you to use `Write-Host` to emit output to the information stream. This enables the **capture** or
> **suppression** of data written using `Write-Host` while preserving backwards compatibility.
>
Expand Down Expand Up @@ -261,8 +261,28 @@ cmdlet sends to it.
separated by a single space. This can be overridden with the **Separator** parameter.

- Non-primitive data types such as objects with properties can cause unexpected results and not
provide meaningful output. For example, `Write-Host @{a = 1; b = 2}` will print
`System.Collections.DictionaryEntry System.Collections.DictionaryEntry` to the host.
provide meaningful output. For example, `@{a = 1; b = 2} | Write-Host` will print
`System.Collections.Hashtable` to the host.

To work around this issue, you can manually create the string format you need with either string
interpolation or the format operator (`-f`). You can also pass the object to the
[Out-String](Out-String.md) command before passing it to `Write-Host`. The following snippet
shows examples of each approach:

```powershell
$ht = @{a = 1; b = 2}
# String interpolation
$ht.Keys.ForEach({ "[$_, $($ht[$_])]" }) -join ' ' | Write-Host
# Format operator
"[{0}, {1}] [{2}, {3}]" -f @('a', $ht.a, 'b', $ht.b) | Write-Host
# Out-String
$ht | Out-String | Write-Host -NoNewline
```

For more information about string interpolation, see the article
[Everything you wanted to know about variable substitution in strings](/powershell/scripting/learn/deep-dives/everything-about-string-substitutions).
For more information about the format operator, see
[about_Operators](../Microsoft.PowerShell.Core/About/about_Operators.md#format-operator--f).

## RELATED LINKS

Expand Down
26 changes: 23 additions & 3 deletions reference/7.4/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: 09/26/2023
ms.date: 04/01/2026
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/write-host?view=powershell-7.4&WT.mc_id=ps-gethelp
schema: 2.0.0
title: Write-Host
Expand Down Expand Up @@ -261,8 +261,28 @@ cmdlet sends to it.
separated by a single space. This can be overridden with the **Separator** parameter.

- Non-primitive data types such as objects with properties can cause unexpected results and not
provide meaningful output. For example, `Write-Host @{a = 1; b = 2}` will print
`System.Collections.DictionaryEntry System.Collections.DictionaryEntry` to the host.
provide meaningful output. For example, `@{a = 1; b = 2} | Write-Host` will print
`System.Collections.Hashtable` to the host.

To work around this issue, you can manually create the string format you need with either string
interpolation or the format operator (`-f`). You can also pass the object to the
[Out-String](Out-String.md) command before passing it to `Write-Host`. The following snippet
shows examples of each approach:

```powershell
$ht = @{a = 1; b = 2}
# String interpolation
$ht.Keys.ForEach({ "[$_, $($ht[$_])]" }) -join ' ' | Write-Host
# Format operator
"[{0}, {1}] [{2}, {3}]" -f @('a', $ht.a, 'b', $ht.b) | Write-Host
# Out-String
$ht | Out-String | Write-Host -NoNewline
```

For more information about string interpolation, see the article
[Everything you wanted to know about variable substitution in strings](/powershell/scripting/learn/deep-dives/everything-about-string-substitutions).
For more information about the format operator, see
[about_Operators](../Microsoft.PowerShell.Core/About/about_Operators.md#format-operator--f).

## RELATED LINKS

Expand Down
28 changes: 24 additions & 4 deletions reference/7.5/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: 09/26/2023
ms.date: 04/01/2026
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/write-host?view=powershell-7.5&WT.mc_id=ps-gethelp
schema: 2.0.0
title: Write-Host
Expand Down Expand Up @@ -35,7 +35,7 @@ a string to use to separate displayed objects. The particular result depends on
hosting PowerShell.

> [!NOTE]
> Starting in Windows PowerShell 5.0, `Write-Host` is a wrapper for `Write-Information` This allows
> Starting in Windows PowerShell 5.0, `Write-Host` is a wrapper for `Write-Information`. This allows
> you to use `Write-Host` to emit output to the information stream. This enables the **capture** or
> **suppression** of data written using `Write-Host` while preserving backwards compatibility.
>
Expand Down Expand Up @@ -261,8 +261,28 @@ cmdlet sends to it.
separated by a single space. This can be overridden with the **Separator** parameter.

- Non-primitive data types such as objects with properties can cause unexpected results and not
provide meaningful output. For example, `Write-Host @{a = 1; b = 2}` will print
`System.Collections.DictionaryEntry System.Collections.DictionaryEntry` to the host.
provide meaningful output. For example, `@{a = 1; b = 2} | Write-Host` will print
`System.Collections.Hashtable` to the host.

To work around this issue, you can manually create the string format you need with either string
interpolation or the format operator (`-f`). You can also pass the object to the
[Out-String](Out-String.md) command before passing it to `Write-Host`. The following snippet
shows examples of each approach:

```powershell
$ht = @{a = 1; b = 2}
# String interpolation
$ht.Keys.ForEach({ "[$_, $($ht[$_])]" }) -join ' ' | Write-Host
# Format operator
"[{0}, {1}] [{2}, {3}]" -f @('a', $ht.a, 'b', $ht.b) | Write-Host
# Out-String
$ht | Out-String | Write-Host -NoNewline
```

For more information about string interpolation, see the article
[Everything you wanted to know about variable substitution in strings](/powershell/scripting/learn/deep-dives/everything-about-string-substitutions).
For more information about the format operator, see
[about_Operators](../Microsoft.PowerShell.Core/About/about_Operators.md#format-operator--f).

## RELATED LINKS

Expand Down
28 changes: 24 additions & 4 deletions reference/7.6/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: 09/26/2023
ms.date: 04/01/2026
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/write-host?view=powershell-7.6&WT.mc_id=ps-gethelp
schema: 2.0.0
title: Write-Host
Expand Down Expand Up @@ -35,7 +35,7 @@ a string to use to separate displayed objects. The particular result depends on
hosting PowerShell.

> [!NOTE]
> Starting in Windows PowerShell 5.0, `Write-Host` is a wrapper for `Write-Information` This allows
> Starting in Windows PowerShell 5.0, `Write-Host` is a wrapper for `Write-Information`. This allows
> you to use `Write-Host` to emit output to the information stream. This enables the **capture** or
> **suppression** of data written using `Write-Host` while preserving backwards compatibility.
>
Expand Down Expand Up @@ -261,8 +261,28 @@ cmdlet sends to it.
separated by a single space. This can be overridden with the **Separator** parameter.

- Non-primitive data types such as objects with properties can cause unexpected results and not
provide meaningful output. For example, `Write-Host @{a = 1; b = 2}` will print
`System.Collections.DictionaryEntry System.Collections.DictionaryEntry` to the host.
provide meaningful output. For example, `@{a = 1; b = 2} | Write-Host` will print
`System.Collections.Hashtable` to the host.

To work around this issue, you can manually create the string format you need with either string
interpolation or the format operator (`-f`). You can also pass the object to the
[Out-String](Out-String.md) command before passing it to `Write-Host`. The following snippet
shows examples of each approach:

```powershell
$ht = @{a = 1; b = 2}
# String interpolation
$ht.Keys.ForEach({ "[$_, $($ht[$_])]" }) -join ' ' | Write-Host
# Format operator
"[{0}, {1}] [{2}, {3}]" -f @('a', $ht.a, 'b', $ht.b) | Write-Host
# Out-String
$ht | Out-String | Write-Host -NoNewline
```

For more information about string interpolation, see the article
[Everything you wanted to know about variable substitution in strings](/powershell/scripting/learn/deep-dives/everything-about-string-substitutions).
For more information about the format operator, see
[about_Operators](../Microsoft.PowerShell.Core/About/about_Operators.md#format-operator--f).

## RELATED LINKS

Expand Down