Powershell: Set-Content expects different argument order when -NoNewline is specified

Created on 23 Jul 2020  Â·  1Comment  Â·  Source: PowerShell/PowerShell

PowerShell 7.0.3.

When I type Set-Content aaa bbb, the file aaa is created with the content bbb.
When I type Set-Content -NoNewline aaa bbb, the file bbb is created with the content aaa.

It's quite unexpected (especially that it seems that the documentation doesn't mention that).

(Additionally, when I call Set-Content -NoNewline aaa $specificLongText, I get the blue screen of death on my Windows 10 — though I'm not sure whether it's related to PowerShell, it might be that some other software misbehaves when a file with weird name is tried to be created.)

Steps to reproduce

Set-Content -NoNewline aaa bbb
Get-Content aaa,bbb

Expected behavior

bbb
Get-Content: Cannot find path 'C:\Test\bbb' because it does not exist.

Actual behavior

Get-Content: Cannot find path 'C:\Test\aaa' because it does not exist.
aaa

Environment data

Name                           Value
----                           -----
PSVersion                      7.0.3
PSEdition                      Core
GitCommitId                    7.0.3
OS                             Microsoft Windows 10.0.19041
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Issue-Bug WG-Engine

>All comments

This is a parameter binder bug, assign to myself to further investigation/triage.

Was this page helpful?
0 / 5 - 0 ratings