Rum Get-MrPiplelineInput but get 5 same results

Viewed 36

I run Get-MrPipelineInput -name get-help but get:

ParameterName ParameterType ValueFromPipeline ValueFromPipelineByPropertyName
------------- ------------- ----------------- -------------------------------
Name          System.String             False                            True
Name          System.String             False                            True
Name          System.String             False                            True
Name          System.String             False                            True
Name          System.String             False                            True
Name          System.String             False                            True

Get 4 extra identical results of Name.

Any Problem with my usage of Get-MrPipelienInput?

1 Answers

I don't think you're doing anything wrong here. I think the problem is actually in the code. Get-Help may be structured unlike most/all other PS Cmdlets/Functions, thus not fitting the structure expected by Mike Robbins (the author of this tool).

After fooling around for a couple of minutes, I can see what's happening here. Get-Help has 6 Parameter Sets. In each of those, the only Parameter which allows values from the pipeline is Name. There is a simple improvement that could be made to Mike's Miscellaneous PowerShell Tools Code to make this a better tool.


function Get-MrPipelineInput {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory)]
        [string]$Name,
        
        [System.Management.Automation.WhereOperatorSelectionMode]$Option = 'Default',
        
        [ValidateRange(1, 2147483647)]
        [int]$Records = 2147483647
    )
    $FunctionOutput = [System.Collections.ArrayList]::new()
    (Get-Command -Name $Name).ParameterSets.ForEach{
        $ParameterSet = $PSItem
        $PSItem.Parameters.Where( {
                $_.ValueFromPipeline -or $_.ValueFromPipelineByPropertyName
            }, $Option, $Records).ForEach( {
               $null = $FunctionOutput.Add(
                    [pscustomobject]@{
                        ParameterSetName                   = $ParameterSet.Name
                        ParameterName                   = $_.Name
                        ParameterType                   = $_.ParameterType
                        ValueFromPipeline               = $_.ValueFromPipeline
                        ValueFromPipelineByPropertyName = $_.ValueFromPipelineByPropertyName
                    })
            })
    }
    $FunctionOutput
}

Running this will produce a more easily understandable output:

PS > (Get-MrPipelineInput -Name Get-Help | ft)


ParameterSetName ParameterName ParameterType ValueFromPipeline ValueFromPipelineByPropertyName
---------------- ------------- ------------- ----------------- -------------------------------
AllUsersView     Name          System.String             False                            True
DetailedView     Name          System.String             False                            True
Examples         Name          System.String             False                            True
Parameters       Name          System.String             False                            True
Online           Name          System.String             False                            True
ShowWindow       Name          System.String             False                            True

I hope this was helpful!

Related