Tee-Object
Additional Resources for Tee-Object |
Display Data and Save That Data with One Command http://www.microsoft.com/technet/scriptcenter/topics/msh/cmdlets/tee-object.mspx
|
SYNOPSIS
Pipes object input to a file or variable, then passes the input along the pipeline.
SYNTAX
Tee-Object [-filePath] <string> [-inputObject <psobject>] [<CommonParameters>]
Tee-Object -variable <string> [-inputObject <psobject>] [<CommonParameters>]
DETAILED DESCRIPTION
Pipes object input to a file or variable, then passes the input along the pipeline.
To pipe the input to a file, specify the FilePath parameter. Piped objects are formatted by using the default formatter before they are stored in the specified file.
To store a reference to the input objects in a variable, specify the Variable parameter.
PARAMETERS
-inputObject <psobject>
Specifies the object input to the cmdlet. Enter a variable that contains the objects or type a command or expression that gets the objects.
Required? |
false |
Position? |
named |
Default value |
|
Accept pipeline input? |
true (ByValue) |
Accept wildcard characters? |
false |
-filePath <string>
Specifies the file where the cmdlet stores the object. Accepts wildcards that resolve to a single file.
Required? |
true |
Position? |
1 |
Default value |
|
Accept pipeline input? |
false |
Accept wildcard characters? |
false |
-variable <string>
Assigns a reference to the input objects to the specified variable.
Required? |
true |
Position? |
named |
Default value |
|
Accept pipeline input? |
false |
Accept wildcard characters? |
false |
<CommonParameters>
trace-command parameterbinding {get-alias $input} -pshost -inputobject $a
INPUT TYPE
Any object
RETURN TYPE
Object
NOTES
For more information, type "Get-Help Tee-Object -detailed". For technical information, type "Get-Help Tee-Object -full".
When specifying multiple values for a parameter, use commas to separate the values. For example, "<parameter-name> <value1>, <value2>".
Using Tee-Object with the FilePath parameter has the same effect as the following script block: {$_ |out-file FilePath }.
EXAMPLE 1
get-process | tee-object -filepath C:\Test1\testfile2.txt
This command gets a list of the processes running on the computer and sends the result to a file. Since there is no second path listed, the result will be displayed in the console.
Handles NPM(K)PM(K) WS(K) VM(M) CPU(s) Id ProcessName
------- ----------- ----- ----- ------ -- -----------
83 4 2300 452039 0.30 4032 Hotkey
272 6 1400 394434 0.06 3088 alg
81 3 804 328421 2.45 148 ApntEx
81 4 2008 580838 0.75 3684 Apoint
...
EXAMPLE 2
get-process notepad | tee-object -variable proc |
select-object processname,handles
This command get a list of the processes running on the computer and sends the result to a variable named proc. It then pipes the resulting objects along to Select-Object, which selects the ProcessName and Handles property. Note that the $proc variable includes the default information returned by Get-Process.
ProcessName Handles
----------- -------
notepad 43
notepad 37
notepad 38
notepad 38
RELATED LINKS