Powershell v2 Finding Cmdlet Parameters that Take Pipeline Input

While reading Don Jones Learn Windows PowerShell In a Month of Lunches Chapter 6 touched on how parameters can take pipeline input.  A while back I recall reading some of Jeff Hicks posts in which he touched on the difference between ByValue and ByPropertyValue.  At the time I didnt know anything about the difference, but, it stuck in my head.  So, when Don dug into it a bit I knew it was time to get my head around it.  Although Don did a good job of explaining it I still needed to play with examples.

I tried to come up with a command to get the parameters which take pipeline input so I could know which did what.  My first attempt got me a little further, but, still did not pierce the veil.  I knew Shay had a post about something along these lines.  When I looked it up I could not find exactly what I needed, but, he did remind me that the Format- cmdlets (something Don touched on in another Chapter) had the same expression capacities as Select-Object.  So, I worked on it a bit.  I had to reach out to the Technet forums:
Close to getting command to list all cmdlets with pipeline set to true - missing way to ignore blanks
but, MichalGadja was able to get my the last mile.  I made one final tweak to add a list of the specific properties returned from the search:
Get-Command -CommandType Cmdlet | `
% { $cmdlet = $_.name; Get-Help $cmdlet -parameter * -ErrorAction SilentlyContinue | `
where {$_.pipelineInput -match "true"} | `
select @{l="cmdlet";e={$cmdlet}},name,@{l="By";e={$_.pipelineinput -replace true ,}}}

Related Posts by Categories

0 comments:

Post a Comment