Skip to content

Join-String -InputObject 1,2,3 result is not equal to 1,2,3 | Join-String result. #8610

Closed

Description

@sethvs

Join-String -InputObject 1,2,3 result is not equal to 1,2,3 | Join-String result.

Steps to reproduce

1,2,3 | Join-String
Join-String -InputObject 1,2,3

Expected behavior

123
123

Actual behavior

123
1 2 3

Environment data

Name                           Value
----                           -----
PSVersion                      6.2.0-preview.3
PSEdition                      Core
GitCommitId                    6.2.0-preview.3
OS                             Microsoft Windows 10.0.17763
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. added
    Issue-Discussion
    on Jan 9, 2019
  2. mklement0 commented on Jan 9, 2019

    @mklement0
    Contributor

    Cool, thanks for fixing this; for the general issue with scalar -InputObject parameters, see #4242.

  3. mklement0 commented on Jan 9, 2019

    @mklement0
    Contributor

    Sergey Vasin (@sethvs), in the implementation it may be better to leave -InputObject as a PSObject rather than making it PSObject[], for efficiency - please see the discussion with Rain Sallow (/u/ta11ow) (@vexx32) starting here.

  4. sethvs commented on Jan 9, 2019

    @sethvs
    ContributorAuthor

    Michael Klement (@mklement0) Thanks. I'll leave the decision to maintainers.

  5. added
    Breaking-Change
    on Jan 11, 2019
  6. BrucePay commented on Jan 11, 2019

    @BrucePay
    Collaborator

    Note that this is a breaking change.

  7. mklement0 commented on Jan 11, 2019

    @mklement0
    Contributor

    Bruce Payette (@BrucePay): It's highly likely that this is a Bucket 3: Unlikely Grey Area change:

    Join-String -InputObject 1,2,3

    is currently effectively the same as:

    "$(1,2,3)"
    

    That is, the only operation being performed is the stringification of the input array (implicit joining with $OFS) during parameter binding - Join-String itself is then a no-op, given that it then receives a single input string; in other words: there's nothing left to join.

  8. sethvs commented on Jan 14, 2019

    @sethvs
    ContributorAuthor

    Bruce Payette (@BrucePay) The Join-String cmdlet has been released in preview.3 only and not in official releases.

  9. mklement0 commented on Jan 14, 2019

    @mklement0
    Contributor

    Good point, Sergey Vasin (@sethvs).


    As for how to implement the proposed change:
    PetSerAl has since shown that switching to PSObject[] in an effort to treat -InputObject arguments the same as PSObject-based -InputObject pipeline input doesn't work in all cases: #4242 (comment)


    As for whether to implement the change at all:

    We need to decide whether we even want to support -InputObject argument / pipeline equivalence for collection-enumerating cmdlets such as Join-String (my vote: yes), or whether we should treat -InputObject simply as an auxiliary parameter that facilitates pipeline input but is not to be used directly with arguments - see #4242 (comment)

    If the latter, Join-String -InputObject 1,2,3 would then by design not be (meaningfully) supported, and there'd be nothing to change.

  10. vexx32 commented on Jan 14, 2019

    @vexx32
    Collaborator

    🤔

    I think that from a semantic perspective, having -InputObject be primarily an implementation detail of standard pipeline support isn't necessarily wrong per se? I think it would be better if there were some way via attribute or some such to denote a parameter as Pipeline-Only such that it wouldn't appear in tab completions or be usable for input directly; in this way we could avoid some of the confusion perhaps?

    But whatever option ultimately wins out here... we should also consider that while there is a mostly consistent implementation amongst standard cmdlets, it's not completely consistent, which is a problem: without a consistent and clear example to follow, third-party cmdlets tend to pick and choose whatever they feel is most appropriate more often than not, which seems to lead to less consistent practices in the wider PowerShell community in this regard.

    As a result, I think that opting to change anything here will only have a meaningful impact if we can decide on and then actually enact a consistent implementation across all the standard PowerShell cmdlets.

  11. mklement0 commented on Jan 14, 2019

    @mklement0
    Contributor

    Excellent points, Rain Sallow (/u/ta11ow) (@vexx32) - I'm hoping that a decision on a consistent cross-cmdlet approach will come as a result of the discussion in #4242.

  12. daxian-dbw commented on Jan 23, 2019

    @daxian-dbw
    Member

    I think it would be better if there were some way via attribute or some such to denote a parameter as Pipeline-Only such that it wouldn't appear in tab completions or be usable for input directly

    Just some thoughts: It's useful to use -InputObject directly in case that you already have the collection object handy and want to avoid the unnecessary pipeline binding overhead.
    In the case of calling a cmdlet in C#, disallowing the use of -InputObject directly would mean that you have to pass in the collection object by powershell.Invoke(myCollection)

  13. mklement0 commented on Jan 24, 2019

    @mklement0
    Contributor

    Dongbo Wang (@daxian-dbw): The performance argument is also mentioned in #4242 (comment) and, at the risk of talking myself hoarse, can we please continue the conversation there (#4242)? (I also encourage you to clarify your C# argument - there.)

  14. added a commit that references this issue on Jan 24, 2019
    a9841d9
  15. added a commit that references this issue on Aug 6, 2026
    29da0e2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Breaking-ChangeIssue-DiscussionResolution-FixedWG-Cmdlets

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions