PSv5 brought the -NoNewline switch to the Set-Content (Add-Content) and Out-File cmdlets to allow direct concatenation of the input objects without newlines (strings among the input objects retain their embedded newlines however).
By default, these cmdlets blindly append an additional newline, whereas Out-String currently invariably does that, because it lacks -NoNewline.
For symmetry, Out-String should support -NoNewline too.
Current behavior
> (Out-String -InputObject 'a') -match '^a\r?\n$'
$True # A trailing newline was added.
Desired behavior
> (Out-String -NoNewline -InputObject 'a') -match '^a$'
$True # No trailing newline was added.
Environment data
PowerShell Core v6.0.0-alpha (v6.0.0-alpha.18) on Darwin Kernel Version 16.5.0: Fri Mar 3 16:52:33 PST 2017; root:xnu-3789.51.2~3/RELEASE_X86_64
PSv5 brought the
-NoNewlineswitch to theSet-Content(Add-Content) andOut-Filecmdlets to allow direct concatenation of the input objects without newlines (strings among the input objects retain their embedded newlines however).By default, these cmdlets blindly append an additional newline, whereas
Out-Stringcurrently invariably does that, because it lacks-NoNewline.For symmetry,
Out-Stringshould support-NoNewlinetoo.Current behavior
Desired behavior
Environment data