入力を2箇所に出力する(tee-object)
「tee-object」はUNIXシェルの「tee」に相当します。
「tee-object」:コンソール+ファイルに出力
fileオプションで出力するファイルを指定します。
プロセス一覧をコンソールとファイルに出力する
MSH C:\> get-process | tee-object -file proc.txt Handles NPM(K) PM(K) WS(K) VS(M) CPU(s) Id ProcessName ------- ------ ----- ----- ----- ------ -- ----------- 800 53 24116 35528 170 17.28 1692 CCAPP 370 8 4504 4056 47 2.52 1240 CCEVTMGR (省略)
- 「C:\proc.txt」にもコンソールと同じ内容が出力されます。
「tee-object」:コンソール+変数に出力
variableオプションで出力する変数を指定します。
カレントディレクトリのファイル覧をコンソールと変数に出力する
MSH C:\> get-childitem | tee-object -variable item Directory: FileSystem::C:\ Mode LastWriteTime Length Name ---- ------------- ------ ---- da--- 2005/08/18 0:45 Documents and Settings d---- 2005/09/30 2:06 Inetpub d---- 2004/02/22 22:22 j2sdk1.4.1_06 dar-- 2005/10/26 23:10 Program Files da--- 2005/10/21 1:22 WINNT
変数の中身もコンソールと同様です。
MSH C:\> $item Directory: FileSystem::C:\ Mode LastWriteTime Length Name ---- ------------- ------ ---- da--- 2005/08/18 0:45 Documents and Settings d---- 2005/09/30 2:06 Inetpub d---- 2004/02/22 22:22 j2sdk1.4.1_06 dar-- 2005/10/26 23:10 Program Files da--- 2005/10/21 1:22 WINNT