Skip to content

Instantly share code, notes, and snippets.

@guitarrapc
Created September 5, 2014 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guitarrapc/61efd5baa445ece62504 to your computer and use it in GitHub Desktop.
Save guitarrapc/61efd5baa445ece62504 to your computer and use it in GitHub Desktop.
PowerShell Pipeline Programming Style sample
function PipelineExecuteOnEndProcessingStyle
{
param
(
[parameter(Position = 0, Mandatory = 1, ValueFrompipeline = 1, ValueFromPipelineByPropertyName = 1)]
[string]$hostaddress
)
begin{ $hostaddresses = @() }
process
{
# まとめる
foreach ($h in $hostaddress){ $hostaddresses += $h }
}
end
{
# まとめてとばす
Execute;
}
}
function PipelineExecuteOnEveryProcesseingStyle
{
param
(
[parameter(Position = 0, Mandatory = 1, ValueFrompipeline = 1, ValueFromPipelineByPropertyName = 1)]
[string]$hostaddress
)
begin{ $hostaddresses = @() }
process
{
# 毎回の入力でとばす
foreach ($h in $hostaddress) {$hostaddresses += $h; Execute; }
}
}
function Execute
{
# なんか処理
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment