Pipeline and Parameter (modification of post by view diff)
View followups from halr9000 | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/1427"></script>download | new post
sample by dfinke
- Function Test-Func {
- param(
- [Parameter(ValueFromPipeline=$true, Mandatory=$true, Position=0)]
- [string[]]$ComputerName
- )
- Begin {
- Function Do-Process($p) {
- "Processing $($p)"
- }
- }
- Process {
- if($_) { Do-Process $_ }
- }
- End {
- if($ComputerName) { @($ComputerName) | % {Do-Process $_} }
- }
- }
- Test-Func a,b
- 'a','b' | Test-Func
- Test-Func x
- 'x' | Test-Func
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.
PowerShell Code Repository