Rules/Test-ForPipelineParameter.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function Test-ForPipelineParameter
{
    param(
    [Parameter(ParameterSetName='TestCommandInfo',Mandatory=$true,ValueFromPipeline=$true)]
    [Management.Automation.CommandInfo]
    $CommandInfo
    )
        
    
    process {    
        if ($commandInfo.Parameters.Count) {
            $pipelineParameterExists = $CommandInfo.Parameters.Values | 
                Select-Object -ExpandProperty Attributes | 
                Where-Object { $_.ValueFromPipeline -or $_.ValueFromPipelineByPropertyName } 
                
            if (-not $pipelineParameterExists) {
                Write-Error "The essence of PowerShell is in the Pipeline, by $CommandInfo has no parameters that use it."
                return
            }
        }
    }
}