Question

help format-list outputs the help for format-list.

format-list | help outputs the help for help (get-help).

Was it helpful?

Solution

Help is a function that essentially redirects to:

Get-Help command | more

If you look at this function's definition, you will see that it accepts a positional argument tagged with ValueFromPipelineByPropertyName with an argument of Name.

PS ~\> Get-Content function:help

<#
.FORWARDHELPTARGETNAME Get-Help
.FORWARDHELPCATEGORY Cmdlet
#>
[CmdletBinding(DefaultParameterSetName='AllUsersView')]
param(
    [Parameter(Position=0, ValueFromPipelineByPropertyName=$true)]
    [System.String]
    ${Name},

    # Other arguments deleted for brevity

    [Switch]
    ${Online})
$outputEncoding=[System.Console]::OutputEncoding

      Get-Help @PSBoundParameters | more

This basically means, if it sees an argument with a property called Name, it binds that as an input parameter. So, when you do:

format-list | help

the format-list command is run (and nothing is returned), so the help function thinks it received no arguments.

When you do:

"format-list" | help

You are passing a string argument. The string type does not have a Name prooperty, so you'll get an error message saying that it can't bind the arguments. However, if you tried:

PS ~\> get-command format-list

CommandType     Name                Definition
-----------     ----                ----------
Cmdlet          Format-List         Format-List [[-Property] <Object[]>] [-GroupBy <...

you can see the the command format-list does have a Name property, so if you tried

get-command format-list | help

You get the help for format-list.

OTHER TIPS

The | or "pipe" operator redirects the output of one operation to another. So in this case you are calling format-list, then redirecting the output of that as a parameter to help. help doesn't know what to do with that parameter, so it goes into default behvaior (help for help).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top