You are currently viewing PowerShell Tee-Object Cmdlet

PowerShell Tee-Object Cmdlet

PowerShell Tee-Object Cmdlet

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

In the last blog post, we have discussed Measure-Object cmdlet in PowerShell.

https://cloudaffaire.com/powershell-measure-object-cmdlet/

In this blog post, we will discuss Tee-Object cmdlet in PowerShell. You can use Tee-Object cmdlet to save command output to a file or to a variable. Tee-Object also displays the output in the prompt apart from saving to a variable or file. If Tee-Object is the last command in the pipeline, the command output is displayed at the prompt.

Tee-Object Cmdlet Syntax:

Tee-Object Cmdlet Argument List:

  • Append: Indicates that the cmdlet appends the output to the specified file. Without this parameter, the new content replaces any existing content in the file without warning.
  • FilePath: Specifies a file that this cmdlet saves the object to Wildcard characters are permitted, but must resolve to a single file.
  • InputObject: Specifies the object to be saved and displayed. Enter a variable that contains the objects or type a command or expression that gets the objects. You can also pipe an object to Tee-Object.
  • LiteralPath: Specifies a file that this cmdlet saves the object to. Unlike FilePath, the value of the LiteralPath parameter is used exactly as it is typed.
  • Variable: Specifies a variable that the cmdlet saves the object to. Enter a variable name without the preceding dollar sign ($).

PowerShell Tee-Object Cmdlet:

Save Output Of A Cmdlet To A Variable And Also Display The Output To Command Line In PowerShell:

Save Output Of A Cmdlet To A File And Also Display The Output To Command Line In PowerShell:

Save Output Of A Cmdlet To A File Appending To The Existing Content And Also Display The Output To Command Line In PowerShell:

Save Output Of A Cmdlet To A File And A variable Simultaneously And Also Display The Output To Command Line In PowerShell:

 

Hope you have enjoyed this article. In the next blog post, we will discuss Compare-Object cmdlet in PowerShell.

To get more details on PowerShell, kindly follow below official documentation

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about?view=powershell-5.1

 

This Post Has One Comment

  1. Avatar
    mist42nz

    how do I use powershell Tee with Tar like in Un*x ?

    tar cf – * | tee tar xf -C \backup1 | tar xf -C \backup2

    The powershell tee seems to be crippled like the write-output , ie with some wierd “we know better” internal issues.

Leave a Reply