function Start-Executable {
[CmdletBinding()]
Param (
[String]$Arg1,
[String[]]$Arg2,
[Parameter(ValueFromPipeline=$true, parametersetname="nopipeline")][String[]]$PipeValue
)
Begin {
# Setup code
if($PSCmdlet.ParameterSetName -eq "nopipeline")
{
Write-Host "No pipeline input"
}
else
{
Write-Host "Pipeline input"
}
}
Process {
$PipeValue
}
End {
}
}
This seems to do the trick.
Basically, the parameter is assigned to a parameter set.
If the parameter is used, $pscmdlet.ParameterSetName
contains "nopipeline"
.
If using the pipeline, then $pscmdlet.ParameterSetName
contains "__AllParameterSets"
Sample output:
PS H:\> @("a","b","c") | Start-Executable
Pipeline input
a
b
c
PS H:\> Start-Executable -PipeValue @("a","b","c")
No pipeline input
a
b
c
Edit: Note that this however won't tell you that there is pipeline input. It will tell you whether the named parameter was used.
In other words, this happens:
PS H:\> Start-Executable
Pipeline input