Skip to content

Add a -NoLastNewline switch parameter to Write-Host, Set-Content, Add-Content, Out-File, Out-String #5108

Open

Description

Follow-up to #3684.

With multiple input objects, the -NoNewline switch causes said cmdlets to not only omit a trailing (last) newline, but also not to place newlines between the (output representations of) the input objects on output.

However, perhaps more typically, you want to only suppress a trailing newline, so it would be handy to have a -NoLastNewline parameter (mutually exclusive with -NoNewLine) that does just that.

If #3855 gets implemented, an alias -NoLastDelimiter could be defined, which would effectively turn the application of the delimiter from terminator logic (place delimiter after every item, including the last) into separator logic (place delimiter only between items).

Desired behavior

  • Out-String example:
PS> 'a', 'b' | Out-String -NoLastNewline
a
b

Note that without -NoLastNewLine you'd get a blank line at the end, due to an extraneous newline getting appended, as discussed in #14444 (which asked for -NoLastNewLine to become the default behavior, but that was declined due to backward-compatibility concerns).

  • Write-Host example:
PS> 'a', 'b' | Write-Host -NoLastNewline; Write-Host 'c'
a
bc

Note that with -NoNewline you'd get abc.

Input object-internal (embedded) newlines should be left untouched by both -NoLastNewline and
-NoNewline (though the latter doesn't do so consistently at present - see #5107).

Environment data

PowerShell Core v6.0.0-beta.8

Activity

  1. added
    Issue-Discussion
    on Oct 13, 2017
  2. God-damnit-all commented on Mar 17, 2023

    @God-damnit-all
    Contributor

    -NoTrailingNewline is probably a better name for the switch, even though it's a bit longer.

  3. mklement0 commented on Mar 17, 2023

    @mklement0
    ContributorAuthor

    @ImportTaste, that would work too (and I'm personally open to either), but what makes you prefer trailing over the last? Does the latter strike you as more ambiguous?

    When naming parameters, it's always worth striving for consistency with existing, analogous / conceptually related names. Get-Help * -Parameter *trailing* currently doesn't find anything among the standard cmdlets; Get-Help * -Parameter *last* yields Select-Object, which has a -Last parameter (only loosely related).

    There's also a balance to strike between expressiveness and simplicity of words, especially keeping in mind the large non-native-speaker user base PowerShell has (though you can argue that trailing is well-established).

  4. God-damnit-all commented on Mar 18, 2023

    @God-damnit-all
    Contributor

    @ImportTaste, that would work too (and I'm personally open to either), but what makes you prefer trailing over the last? Does the latter strike you as more ambiguous?

    When naming parameters, it's always worth striving for consistency with existing, analogous / conceptually related names. Get-Help * -Parameter *trailing* currently doesn't find anything among the standard cmdlets; Get-Help * -Parameter *last* yields Select-Object, which has a -Last parameter (only loosely related).

    There's also a balance to strike between expressiveness and simplicity of words, especially keeping in mind the large non-native-speaker user base PowerShell has (though you can argue that trailing is well-established).

    It's a more intuitive label because it implies the existence of a superfluous linebreak for those that aren't already aware of this annoying PowerShell quirk.

    To put it another way,I didn't used to be aware that the extra linebreak added at the end was actually a part of the string itself, I thought it was just the shell doing that.

    -NoExtraNewline would also work, I suppose.

  5. added
    Resolution-No Activity
    on Nov 16, 2023
  6. cow1337killer3 commented on Jul 7, 2026

    @cow1337killer3

    Make it happen

  7. added
    WG-NeedsReview
    and removed
    Resolution-No Activity
    on Jul 8, 2026
  8. moved this from Queue to In-Progress-Issues in Cmdlets Working Groupon Aug 5, 2026
  9. SteveL-MSFT commented on Aug 5, 2026

    @SteveL-MSFT
    Member

    @PowerShell/wg-powershell-cmdlets discussed this, we agree with the need and proposed new switch and agree that -NoLastNewline is probably best option given that -Last is used already.

  10. moved this from In-Progress-Issues to Reviewed in Cmdlets Working Groupon Aug 5, 2026
  11. added
    WG-Reviewed
    Issue-Enhancement
    Up-for-Grabs
    and removed
    WG-NeedsReview
    Issue-Discussion
    on Aug 5, 2026
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

    Issue-EnhancementUp-for-GrabsWG-CmdletsWG-Reviewed

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions