|
2 | 2 | external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml |
3 | 3 | Locale: en-US |
4 | 4 | Module Name: Microsoft.PowerShell.Utility |
5 | | -ms.date: 12/12/2022 |
| 5 | +ms.date: 09/17/2025 |
6 | 6 | online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/tee-object?view=powershell-5.1&WT.mc_id=ps-gethelp |
7 | 7 | schema: 2.0.0 |
8 | 8 | aliases: |
@@ -37,10 +37,14 @@ Tee-Object [-InputObject <PSObject>] -Variable <String> [<CommonParameters>] |
37 | 37 |
|
38 | 38 | ## DESCRIPTION |
39 | 39 |
|
40 | | -The `Tee-Object` cmdlet redirects output, that is, it sends the output of a command in two |
41 | | -directions (like the letter T). It stores the output in a file or variable and also sends it down |
42 | | -the pipeline. If `Tee-Object` is the last command in the pipeline, the command output is displayed |
43 | | -at the prompt. |
| 40 | +The `Tee-Object` cmdlet write output in two directions. It stores the output in a file or variable |
| 41 | +and also sends it down the pipeline. If `Tee-Object` is the last command in the pipeline, the |
| 42 | +command output is displayed in the console. |
| 43 | + |
| 44 | +Internally, `Tee-Object` uses the `Set-Variable` and `Out-File` commands. These commands support the |
| 45 | +**WhatIf** parameter. The `Tee-Object` command doesn't support the **WhatIf** parameter. However, if |
| 46 | +you wrap `Tee-Object` in a script or function that support the **WhatIf** parameter, `Tee-Object` |
| 47 | +passes the state of **WhatIf** to the `Set-Variable` and `Out-File` commands. |
44 | 48 |
|
45 | 49 | ## EXAMPLES |
46 | 50 |
|
@@ -99,6 +103,31 @@ drive. A pipeline operator (`|`) sends the list to `Tee-Object`, which appends t |
99 | 103 | AllSystemFiles.txt file and passes the list down the pipeline to the `Out-File` cmdlet, which saves |
100 | 104 | the list in the `NewSystemFiles.txt file`. |
101 | 105 |
|
| 106 | +### Example 4: Use `Tee-Object` in a script with the **WhatIf** parameter |
| 107 | + |
| 108 | +The `Tee-Object` command doesn't support the **WhatIf** parameter. However, if you wrap `Tee-Object` |
| 109 | +in a script or function that support the **WhatIf** parameter, `Tee-Object` passes the state of |
| 110 | +**WhatIf** to the `Set-Variable` and `Out-File` commands it uses internally. |
| 111 | + |
| 112 | +```powershell |
| 113 | +PS> function Test-Tee { |
| 114 | + [Cmdletbinding(SupportsShouldProcess)] |
| 115 | + Param() |
| 116 | + $true|tee -Variable b |
| 117 | + "Variable `$b is set to '$b'" |
| 118 | +} |
| 119 | +
|
| 120 | +PS> Test-Tee |
| 121 | +
|
| 122 | +True |
| 123 | +Variable $b is set to 'True' |
| 124 | +
|
| 125 | +PS> Test-Tee -WhatIf |
| 126 | +True |
| 127 | +What if: Performing the operation "Set variable" on target "Name: b Value: True". |
| 128 | +Variable $b is set to '' |
| 129 | +``` |
| 130 | + |
102 | 131 | ## PARAMETERS |
103 | 132 |
|
104 | 133 | ### -Append |
|
0 commit comments