名前 Tee-Object 概要 Saves command output in a file or variable and also sends it down the pipeline. 構文 Tee-Object [-FilePath] [-Append] [-InformationAction {SilentlyContinue | Stop | Continue | Inquire | Ig nore | Suspend}] [-InformationVariable []] [-InputObject []] [] Tee-Object [-InformationAction {SilentlyContinue | Stop | Continue | Inquire | Ignore | Suspend}] [-InformationV ariable []] [-InputObject []] -LiteralPath [] Tee-Object [-InformationAction {SilentlyContinue | Stop | Continue | Inquire | Ignore | Suspend}] [-InformationV ariable []] [-InputObject []] -Variable [] 説明 The Tee-Object cmdlet redirects output, that is, it sends the output of a command in two directions (like the le tter "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. パラメーター -Append [] Appends the output to the specified file. Without this parameter, the new content replaces any existing cont ent in the file without warning. This parameter is introduced in Windows PowerShell 3.0. 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -FilePath Saves the object in the specified file. Wildcard characters are permitted, but must resolve to a single file . 必須 true 位置 1 既定値 None パイプライン入力を許可する false ワイルドカード文字を許可する false -InformationAction [] This parameter is introduced in Windows PowerShell 3.0. 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -InformationVariable [] This parameter is introduced in Windows PowerShell 3.0. 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -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. When you use the InputObject parameter with Tee-Object, instead of piping command results to Tee-Object, the InputObject value―even if the value is a collection that is the result of a command, such as InputObject ( Get-Process)―is treated as a single object. Because InputObject cannot return individual properties from an array or collection of objects, it is recommended that if you use Tee-Object to perform operations on a coll ection of objects for those objects that have specific values in defined properties, you use Tee-Object in t he pipeline, as shown in the examples in this topic. 必須 false 位置 named 既定値 none パイプライン入力を許可する true (ByValue) ワイルドカード文字を許可する false -Variable Saves the object in the specified variable. Enter a variable name without the preceding dollar sign ($). 必須 true 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -LiteralPath Saves the object in the specified file. Unlike FilePath, the value of the LiteralPath parameter is used exac tly as it is typed. No characters are interpreted as wildcards. If the path includes escape characters, encl ose it in single quotation marks. Single quotation marks tell Windows PowerShell not to interpret any charac ters as escape sequences. 必須 true 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false このコマンドレットは、次の共通パラメーターをサポートします: Verbose、 Debug、ErrorAction、ErrorVariable、WarningAction、WarningVariable、 OutBuffer, PipelineVariable、および OutVariable。詳細については、 about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216) を参照してください。 入力 System.Management.Automation.PSObject You can pipe objects to Tee-Object. 出力 System.Management.Automation.PSObject Tee-Object returns the object that it redirects. メモ You can also use the Out-File cmdlet or the redirection operator, both of which save the output in a file bu t do not send it down the pipeline. Tee-Object uses Unicode encoding when it writes to files. As a result, the output might not be formatted pro perly in files with a different encoding. To specify the encoding, use the Out-File cmdlet. -------------------------- EXAMPLE 1 -------------------------- PS C:\>get-process | tee-object -filepath C:\Test1\testfile2.txt Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName ------- ------ ----- ----- ----- ------ -- ----------- 83 4 2300 4520 39 0.30 4032 00THotkey 272 6 1400 3944 34 0.06 3088 alg 81 3 804 3284 21 2.45 148 ApntEx 81 4 2008 5808 38 0.75 3684 Apoint ... This command gets a list of the processes running on the computer and sends the result to a file. Because a seco nd path is not specified, the processes are also displayed in the console. -------------------------- EXAMPLE 2 -------------------------- PS C:\>get-process notepad | tee-object -variable proc | select-object processname,handles ProcessName Handles ----------- ------- notepad 43 notepad 37 notepad 38 notepad 38 This command gets 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 propert y. Note that the $proc variable includes the default information returned by Get-Process. -------------------------- EXAMPLE 3 -------------------------- PS C:\>get-childitem path D: file system recurse | tee-object file c:\test\AllSystemFiles.txt append | out -file c:\test\NewSystemFiles.txt This command saves a list of system files in a two log files, a cumulative file and a current file. The command uses the Get-ChildItem cmdlet to do a recursive search for system files on the D: drive. A pipeline operator (|) sends the list to Tee-Object, which appends the list to the AllSystemFiles.txt file and passes the list down the pipeline to the Out-File cmdlet, which saves the list in the NewSystemFiles.txt file. 関連するリンク Online Version: http://go.microsoft.com/fwlink/p/?linkid=294019 Select-Object about_Redirection