配列に対する操作 - ForEach-Object

エイリアス

 1,2,3 | ForEach-Object { New-Item -type f ([String] $_ + ".txt") }  
 1,2,3 | foreach { New-Item -type f ([String] $_ + ".txt") }  
 1,2,3 | % {  New-Item -type f ([String] $_ + ".txt") }  
 => 1.txt 
    2.txt 
    3.txt 
 

Where-Objectと組み合わせて

 1..6 | ? { $_ % 2 -eq 0 } | % { "DEBUG: " + $_ } 
 => DEBUG: 2 
    DEBUG: 4  
    DEBUG: 6

Begin/Process/Endブロック

 dir *.txt | % -Begin { $sum = 0 } -Process { $sum += $_.length } -End { "File Size: " + $sum + " bytes" }

参考

http://technet.microsoft.com/ja-jp/library/dd347608.aspx


トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS

Last-modified: 2012-09-30 (日) 18:44:53