question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Suggestion: make it easier to discover which cmdlet parameters accept pipeline input, via the syntax diagram

See original GitHub issue

Related: #4715 and #4626.

Currently, it is not easy to discover which of a given cmdlet’s / advanced function’s parameters accept pipeline input and how (by value and/or by property name):

Using the example of Rename-Item:

  • You can use Get-Help Rename-Item -Full and then browse the entire topic for Accept pipeline input? lines

  • You can use a nontrivial command such as the following:
    Get-Help Rename-Item -Parameter * | ? pipelineInput -like 'true*' | Select-Object Name, Type, pipelineInput

The above yields:


name        type                       pipelineInput                 
----        ----                       -------------                 
Credential  @{name=PSCredential; uri=} true (ByPropertyName)         
LiteralPath @{name=String; uri=}       true (ByPropertyName)         
NewName     @{name=String; uri=}       true (ByPropertyName)         
Path        @{name=String; uri=}       true (ByValue, ByPropertyName)

Neither option is convenient.

Perhaps the syntax diagrams could be enhanced with symbols that reflect pipeline-binding behavior?

Something along the lines of (these are mere examples; the idea is to be concise):

  • | … by value (only)
  • … by property name (only)
  • |⌠ … by both value and property name

Applied to the Rename-Item example, with the symbols placed inside (...) after the parameter (for example):

Rename-Item [-Path(|⌠)] <String> [-NewName] <String> [-Credential(⌠) <PSCredential>] [-Force] [-PassThru] [-Confirm] [-WhatIf] [-UseTransaction <SwitchParameter>] 
    [<CommonParameters>]
    
Rename-Item [-NewName(⌠)] <String> [-Credential(⌠) <PSCredential>] [-Force] [-PassThru] -LiteralPath(⌠) <String> [-Confirm] [-WhatIf] [-UseTransaction <SwitchParameter>] 
    [<CommonParameters>]

Note: A crucial piece missing from the above is that parameters have aliases and that binding by property name often happens via those aliases; e.g., Select-String’s -LiteralPath has an alias of PSPath, and when you pipe Get-ChildItem output to Select-String, the objects bind by .PSPath, not .LiteralPath.

Written as of PowerShell Core v6.0.0-beta.3.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
rkeithhillcommented, Jun 28, 2017

This is somewhat orthogonal to the Get-Command -Syntax request but a number of us PS users, rely on a command called Get-Parameter to get this info. It comes with the PSCX module. Here’s the output from this command for Rename-Item:

PS C:\> Get-Parameter Rename-Item

    Command: Microsoft.PowerShell.Management/Rename-Item
    Set:    ByPath *


Name                   Aliases      Position Mandatory Pipeline ByName Provider        Type
----                   -------      -------- --------- -------- ------ --------        ----
Confirm                {cf}         Named    False     False    False  All             SwitchParameter
Credential             {Cr*}        Named    False     False    True   All             PSCredential
Force                  {F*}         Named    False     False    False  All             SwitchParameter
NewName                {N*}         1        True      False    True   All             String
PassThru               {Pas*}       Named    False     False    False  All             SwitchParameter
Path                   {Pat*}       0        True      True     True   All             String
UseTransaction         {usetx}      Named    False     False    False  All             SwitchParameter
WhatIf                 {wi}         Named    False     False    False  All             SwitchParameter


    Command: Microsoft.PowerShell.Management/Rename-Item
    Set:    ByLiteralPath


Name                   Aliases      Position Mandatory Pipeline ByName Provider        Type
----                   -------      -------- --------- -------- ------ --------        ----
Confirm                {cf}         Named    False     False    False  All             SwitchParameter
Credential             {Cr*}        Named    False     False    True   All             PSCredential
Force                  {F*}         Named    False     False    False  All             SwitchParameter
LiteralPath            {PSPath, L*} Named    True      False    True   All             String
NewName                {N*}         1        True      False    True   All             String
PassThru               {Pas*}       Named    False     False    False  All             SwitchParameter
UseTransaction         {usetx}      Named    False     False    False  All             SwitchParameter
WhatIf                 {wi}         Named    False     False    False  All             SwitchParameter

Personally, I find this far easier to parse than the output of Get-Command -Syntax.

1reaction
dragonwolf83commented, Jun 29, 2017

Prefixing the command doesn’t help if another module uses it and didn’t prefix it themselves. You could use Import-Module -Prefix "CX" -Name PSCX to explicitly load PSCX with a custom prefix, though that would not be good for code re-use.

What I do is modify the PSD1 file in the module directory to comment it out from CmdletsToExport. However, it would be lost in an upgrade and need to be redone if that command is still there.

Read more comments on GitHub >

github_iconTop Results From Across the Web

about Pipelines - PowerShell
Use the Get-Help command with the Full or Parameter options to determine which parameters of a cmdlet accept pipeline input.
Read more >
PowerShell: Getting Started - Accepting Pipeline Input
Accepting pipeline input is possible via parameter attributes available when using [cmdletbinding()]. There are two different parameter ...
Read more >
How to call "Invoke-MgSubscribeGroup"?
GitHub issue #4135 proposes making syntax diagrams directly reflect which parameters accept pipeline input. What complicates matters with ...
Read more >
Ingest pipelines | Elasticsearch Guide [8.9]
A pipeline consists of a series of configurable tasks called processors. Each processor runs sequentially, making specific changes to incoming documents. After ...
Read more >
Pipeline: Input Step
This step pauses Pipeline execution and allows the user to interact and control the flow of the build. Only a basic "proceed" or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found