PoshCode Logo PowerShell Code Repository

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

  1. Function Test-Func {
  2.  
  3.     param(
  4.         [Parameter(ValueFromPipeline=$true, Mandatory=$true, Position=0)]
  5.         [string[]]$ComputerName
  6.     )
  7.    
  8.     Begin {
  9.         Function Do-Process($p) {
  10.             "Processing $($p)"
  11.         }
  12.     }
  13.    
  14.     Process {
  15.         if($_) { Do-Process $_ }
  16.     }
  17.    
  18.     End {
  19.         if($ComputerName) { @($ComputerName) | % {Do-Process $_} }
  20.     }
  21. }
  22.  
  23. Test-Func a,b
  24. 'a','b' | Test-Func
  25. Test-Func x
  26. '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.

Syntax highlighting:


Remember me