Chapter 9
Activities
- Nothing, because our parameter is not written to accept pipeline input. As we discovered in Chapter 8, Writing Our First Script – Turning Simple Cmdlets into Reusable Code, to allow a parameter to accept pipeline input, we must add a parameter argument, like this:
Figure A.11 – Accepting values from the pipeline
On line 9
, we’ve added a ValueFromPipeline
argument to the parameter, which allows it to accept values from the pipeline. We’ve also enclosed the function in a process
block, opening on line 12
and closing on line 20
; if we don’t have a process
block, then the function will only act on the last value in the pipeline.
- Because
Get-Random
only accepts one positional parameter,-Maximum
. If we run it as previously, then the maximum will be set as15
, and the cmdlet has no idea what to do with the20
value. Similarly,Get-Fifteen20 15 -maximum 20
won’t work because the...