Skip to content

Instantly share code, notes, and snippets.

@JohnLBevan
Created October 20, 2014 12:22
Show Gist options
  • Save JohnLBevan/134bf5bbf1ffbc8fa179 to your computer and use it in GitHub Desktop.
Save JohnLBevan/134bf5bbf1ffbc8fa179 to your computer and use it in GitHub Desktop.
Demo of how to get content from pipeline
powershell
cls
function testme {
param(
[Parameter(
Position=0,
Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true)
]
[String[]]$Message
)
begin {
$elementsProcessed = 0
write-host "testme called"
}
process {
write-host $message
$elementsProcessed++
}
end {
write-host ("{0} messages were processed from the pipeline" -f $elementsProcessed)
}
}
testme 3
5..15 | %{"message #{0:00}" -f $_} | testme
Output:
PS H:\> testme 3
testme called
3
1 messages were processed from the pipeline
PS H:\> 5..15 | %{"message #{0:00}" -f $_} | testme
testme called
message #05
message #06
message #07
message #08
message #09
message #10
message #11
message #12
message #13
message #14
message #15
11 messages were processed from the pipeline
PS H:\>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment