6
解説:パイプ入力から読み込むpowershell関数をどのように記述しますか?
以下は、パイプ入力を使用する関数/スクリプトの最も単純な例です。それぞれは、 "echo"コマンドレットへのパイプラインと同じように動作します。スクリプトとして
Function Echo-Pipe {
Begin {
# Executes once before first item in pipeline is processed
}
Process {
# Executes once for each pipeline object
echo $_
}
End {
# Executes once after last pipeline object is processed
}
}
Function Echo-Pipe2 {
foreach ($i in $input) {
$i
}
}
:
#エコーPipe.ps1Begin {
# Executes once before first item in pipeline is processed
}
Process {
# Executes once for each pipeline object
echo $_
}
End {
# Executes once after last pipeline object is processed
}
#エコーPipe2.ps1 例えば
foreach ($i in $input) {
$i
}
機能として
PS > . theFileThatContainsTheFunctions.ps1 # This includes the functions into your session
PS > echo "hello world" | Echo-Pipe
hello world
PS > cat aFileWithThreeTestLines.txt | Echo-Pipe2
The first test line
The second test line
The third test line