You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add a -NoLastNewline switch parameter to Write-Host, Set-Content, Add-Content, Out-File, Out-String #5108
Issue-Enhancementthe issue is more of a feature request than a bugUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdletsgeneral cmdlet issuesWG-ReviewedA Working Group has reviewed this and made a recommendation
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
Reacted by Yuya Kusakabe, zett42, erose96, 90jroman, Tyler and surfingoldelephant
@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).
@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.
@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.
Issue-Enhancementthe issue is more of a feature request than a bugUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdletsgeneral cmdlet issuesWG-ReviewedA Working Group has reviewed this and made a recommendation
Activity
God-damnit-all commentedon Mar 17, 2023
-NoTrailingNewlineis probably a better name for the switch, even though it's a bit longer.mklement0 commentedon Mar 17, 2023
@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*yieldsSelect-Object, which has a-Lastparameter (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).
God-damnit-all commentedon Mar 18, 2023
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.
-NoExtraNewlinewould also work, I suppose.cow1337killer3 commentedon Jul 7, 2026
Make it happen
SteveL-MSFT commentedon Aug 5, 2026
@PowerShell/wg-powershell-cmdlets discussed this, we agree with the need and proposed new switch and agree that
-NoLastNewlineis probably best option given that-Lastis used already.