diff --git a/reference/5.1/Microsoft.PowerShell.Utility/Tee-Object.md b/reference/5.1/Microsoft.PowerShell.Utility/Tee-Object.md index 567939931b8..f7b50b68dc1 100644 --- a/reference/5.1/Microsoft.PowerShell.Utility/Tee-Object.md +++ b/reference/5.1/Microsoft.PowerShell.Utility/Tee-Object.md @@ -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/17/2025 online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/tee-object?view=powershell-5.1&WT.mc_id=ps-gethelp schema: 2.0.0 aliases: @@ -37,10 +37,14 @@ Tee-Object [-InputObject ] -Variable [] ## DESCRIPTION -The `Tee-Object` cmdlet redirects output, that is, it sends the output of a command in two -directions (like the letter T). It stores the output in a file or variable and also sends it down -the pipeline. If `Tee-Object` is the last command in the pipeline, the command output is displayed -at the prompt. +The `Tee-Object` cmdlet write output in two directions. It stores the output in a file or variable +and also sends it down the pipeline. If `Tee-Object` is the last command in the pipeline, the +command output is displayed in the console. + +Internally, `Tee-Object` uses the `Set-Variable` and `Out-File` commands. These commands support the +**WhatIf** parameter. The `Tee-Object` command doesn't support the **WhatIf** parameter. However, if +you wrap `Tee-Object` in a script or function that support the **WhatIf** parameter, `Tee-Object` +passes the state of **WhatIf** to the `Set-Variable` and `Out-File` commands. ## EXAMPLES @@ -99,6 +103,31 @@ drive. A pipeline operator (`|`) sends the list to `Tee-Object`, which appends t AllSystemFiles.txt file and passes the list down the pipeline to the `Out-File` cmdlet, which saves the list in the `NewSystemFiles.txt file`. +### Example 4: Use `Tee-Object` in a script with the **WhatIf** parameter + +The `Tee-Object` command doesn't support the **WhatIf** parameter. However, if you wrap `Tee-Object` +in a script or function that support the **WhatIf** parameter, `Tee-Object` passes the state of +**WhatIf** to the `Set-Variable` and `Out-File` commands it uses internally. + +```powershell +PS> function Test-Tee { + [Cmdletbinding(SupportsShouldProcess)] + Param() + $true|tee -Variable b + "Variable `$b is set to '$b'" +} + +PS> Test-Tee + +True +Variable $b is set to 'True' + +PS> Test-Tee -WhatIf +True +What if: Performing the operation "Set variable" on target "Name: b Value: True". +Variable $b is set to '' +``` + ## PARAMETERS ### -Append diff --git a/reference/7.4/Microsoft.PowerShell.Utility/Tee-Object.md b/reference/7.4/Microsoft.PowerShell.Utility/Tee-Object.md index f09089da4d4..a1cd86cd3b9 100644 --- a/reference/7.4/Microsoft.PowerShell.Utility/Tee-Object.md +++ b/reference/7.4/Microsoft.PowerShell.Utility/Tee-Object.md @@ -2,7 +2,7 @@ external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml Locale: en-US Module Name: Microsoft.PowerShell.Utility -ms.date: 04/25/2023 +ms.date: 09/17/2025 online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/tee-object?view=powershell-7.4&WT.mc_id=ps-gethelp schema: 2.0.0 aliases: @@ -37,10 +37,14 @@ Tee-Object [-InputObject ] -Variable [] ## DESCRIPTION -The `Tee-Object` cmdlet redirects output, that is, it sends the output of a command in two -directions (like the letter T). It stores the output in a file or variable and also sends it down -the pipeline. If `Tee-Object` is the last command in the pipeline, the command output is displayed -at the prompt. +The `Tee-Object` cmdlet write output in two directions. It stores the output in a file or variable +and also sends it down the pipeline. If `Tee-Object` is the last command in the pipeline, the +command output is displayed in the console. + +Internally, `Tee-Object` uses the `Set-Variable` and `Out-File` commands. These commands support the +**WhatIf** parameter. The `Tee-Object` command doesn't support the **WhatIf** parameter. However, if +you wrap `Tee-Object` in a script or function that support the **WhatIf** parameter, `Tee-Object` +passes the state of **WhatIf** to the `Set-Variable` and `Out-File` commands. ## EXAMPLES @@ -151,6 +155,31 @@ and comparing that string to `$frontMatterPattern`. Finally, the example prints the names of the files in the folder that have a defined front matter metadata block. +### Example 5: Use `Tee-Object` in a script with the **WhatIf** parameter + +The `Tee-Object` command doesn't support the **WhatIf** parameter. However, if you wrap `Tee-Object` +in a script or function that support the **WhatIf** parameter, `Tee-Object` passes the state of +**WhatIf** to the `Set-Variable` and `Out-File` commands it uses internally. + +```powershell +PS> function Test-Tee { + [Cmdletbinding(SupportsShouldProcess)] + Param() + $true|tee -Variable b + "Variable `$b is set to '$b'" +} + +PS> Test-Tee + +True +Variable $b is set to 'True' + +PS> Test-Tee -WhatIf +True +What if: Performing the operation "Set variable" on target "Name: b Value: True". +Variable $b is set to '' +``` + ## PARAMETERS ### -Append diff --git a/reference/7.5/Microsoft.PowerShell.Utility/Tee-Object.md b/reference/7.5/Microsoft.PowerShell.Utility/Tee-Object.md index 30abb83a2b2..c19e923c335 100644 --- a/reference/7.5/Microsoft.PowerShell.Utility/Tee-Object.md +++ b/reference/7.5/Microsoft.PowerShell.Utility/Tee-Object.md @@ -2,7 +2,7 @@ external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml Locale: en-US Module Name: Microsoft.PowerShell.Utility -ms.date: 04/25/2023 +ms.date: 09/17/2025 online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/tee-object?view=powershell-7.5&WT.mc_id=ps-gethelp schema: 2.0.0 aliases: @@ -37,10 +37,14 @@ Tee-Object [-InputObject ] -Variable [] ## DESCRIPTION -The `Tee-Object` cmdlet redirects output, that is, it sends the output of a command in two -directions (like the letter T). It stores the output in a file or variable and also sends it down -the pipeline. If `Tee-Object` is the last command in the pipeline, the command output is displayed -at the prompt. +The `Tee-Object` cmdlet write output in two directions. It stores the output in a file or variable +and also sends it down the pipeline. If `Tee-Object` is the last command in the pipeline, the +command output is displayed in the console. + +Internally, `Tee-Object` uses the `Set-Variable` and `Out-File` commands. These commands support the +**WhatIf** parameter. The `Tee-Object` command doesn't support the **WhatIf** parameter. However, if +you wrap `Tee-Object` in a script or function that support the **WhatIf** parameter, `Tee-Object` +passes the state of **WhatIf** to the `Set-Variable` and `Out-File` commands. ## EXAMPLES @@ -151,6 +155,31 @@ and comparing that string to `$frontMatterPattern`. Finally, the example prints the names of the files in the folder that have a defined front matter metadata block. +### Example 5: Use `Tee-Object` in a script with the **WhatIf** parameter + +The `Tee-Object` command doesn't support the **WhatIf** parameter. However, if you wrap `Tee-Object` +in a script or function that support the **WhatIf** parameter, `Tee-Object` passes the state of +**WhatIf** to the `Set-Variable` and `Out-File` commands it uses internally. + +```powershell +PS> function Test-Tee { + [Cmdletbinding(SupportsShouldProcess)] + Param() + $true|tee -Variable b + "Variable `$b is set to '$b'" +} + +PS> Test-Tee + +True +Variable $b is set to 'True' + +PS> Test-Tee -WhatIf +True +What if: Performing the operation "Set variable" on target "Name: b Value: True". +Variable $b is set to '' +``` + ## PARAMETERS ### -Append diff --git a/reference/7.6/Microsoft.PowerShell.Utility/Tee-Object.md b/reference/7.6/Microsoft.PowerShell.Utility/Tee-Object.md index f8aa187a25a..4797353a8e7 100644 --- a/reference/7.6/Microsoft.PowerShell.Utility/Tee-Object.md +++ b/reference/7.6/Microsoft.PowerShell.Utility/Tee-Object.md @@ -2,7 +2,7 @@ external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml Locale: en-US Module Name: Microsoft.PowerShell.Utility -ms.date: 04/25/2023 +ms.date: 09/17/2025 online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/tee-object?view=powershell-7.6&WT.mc_id=ps-gethelp schema: 2.0.0 aliases: @@ -37,10 +37,14 @@ Tee-Object [-InputObject ] -Variable [] ## DESCRIPTION -The `Tee-Object` cmdlet redirects output, that is, it sends the output of a command in two -directions (like the letter T). It stores the output in a file or variable and also sends it down -the pipeline. If `Tee-Object` is the last command in the pipeline, the command output is displayed -at the prompt. +The `Tee-Object` cmdlet write output in two directions. It stores the output in a file or variable +and also sends it down the pipeline. If `Tee-Object` is the last command in the pipeline, the +command output is displayed in the console. + +Internally, `Tee-Object` uses the `Set-Variable` and `Out-File` commands. These commands support the +**WhatIf** parameter. The `Tee-Object` command doesn't support the **WhatIf** parameter. However, if +you wrap `Tee-Object` in a script or function that support the **WhatIf** parameter, `Tee-Object` +passes the state of **WhatIf** to the `Set-Variable` and `Out-File` commands. ## EXAMPLES @@ -151,6 +155,31 @@ and comparing that string to `$frontMatterPattern`. Finally, the example prints the names of the files in the folder that have a defined front matter metadata block. +### Example 5: Use `Tee-Object` in a script with the **WhatIf** parameter + +The `Tee-Object` command doesn't support the **WhatIf** parameter. However, if you wrap `Tee-Object` +in a script or function that support the **WhatIf** parameter, `Tee-Object` passes the state of +**WhatIf** to the `Set-Variable` and `Out-File` commands it uses internally. + +```powershell +PS> function Test-Tee { + [Cmdletbinding(SupportsShouldProcess)] + Param() + $true|tee -Variable b + "Variable `$b is set to '$b'" +} + +PS> Test-Tee + +True +Variable $b is set to 'True' + +PS> Test-Tee -WhatIf +True +What if: Performing the operation "Set variable" on target "Name: b Value: True". +Variable $b is set to '' +``` + ## PARAMETERS ### -Append