Skip to content

Commit

Permalink
new, simpler pipeline piping template
Browse files Browse the repository at this point in the history
  • Loading branch information
ninmonkey committed Feb 1, 2024
1 parent 9304937 commit 6ad2935
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Pwsh/Pipeline/Template-ParameterAsPipelineOrParam.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
function Test-NumberInRange{
<#
.EXAMPLE
Test-NumberInRange -in (0..4) -Start 2 -End 5
0..4 | Test-NumberInRange -Start 2 -End 5
0..4 | Test-NumberInRange 2 4
#>
[CmdletBinding(DefaultParameterSetName='FromPipe')]
param(
[Alias('InObj', 'Items')]
[Parameter( Mandatory, ParameterSetName='FromPipe', ValueFromPipeline )]
[Parameter( Mandatory, ParameterSetName='FromParam', Position = 0 )]
[ValidateNotNull()]
[int32[]] $InputObject,

[Alias('Start')]
[Parameter( Mandatory, ParameterSetName='FromPipe', Position = 0 )]
[Parameter( Mandatory, ParameterSetName='FromParam', Position = 1 )]
[ValidateNotNull()]
[int32] $RangeStart,

[Alias('End')]
[Parameter( Mandatory, ParameterSetName='FromPipe', Position = 1 )]
[Parameter( Mandatory, ParameterSetName='FromParam', Position = 2 )]
[ValidateNotNull()]
[int32] $RangeEnd
)
process {
# $PSBoundParameters | Json -Compress | write-host -fg 'gray80' -bg 'gray50'
foreach($Item in $InputObject) {
if( $Item -ge $RangeStart -and $Item -le $RangeEnd ) {
$Item
}
}
}
}

0 comments on commit 6ad2935

Please sign in to comment.