Splatting behaves strange

by megamorf at 2012-12-09 02:32:08

Hello everybody,

I’m rewriting this out-wiki Script http://dmitrysotnikov.wordpress.com/200 … ki-format/ and stumbled upon a strange behaviour of passing a hashtable as parameter collection.

Here’s a short test function to show what bothers me:

function test-splat {

$filePath = "C:\temp\test-splat.txt"
new-item -path $filepath -ItemType "File" -force | out-null

$params = @{FilePath = $filePath;Append = $true}

@"
1111
2222
3333
4444
----
"@| Out-File @params

@"
5555
6666
7777
8888
"@| Out-File -Append:$true -FilePath $filePath

ii $filepath

}

test-splat


This is the output:

1111222233334444----
5555
6666
7777
8888

Can somebody explain whats going on?
by Makovec at 2012-12-09 05:29:11
Hi,
not sure why you received this. When I tried in my session I got expected results. In ISE and also in the console.
[list]1111
2222
3333
4444
----
5555
6666
7777
8888[/list]
What version of PowerShell you use?

David
by megamorf at 2012-12-09 05:39:49
I’m using ISEv3 on Windows 7 SP1

PS C:> $psversiontable

Name Value
---- -----
WSManStackVersion 3.0
PSCompatibleVersions {1.0, 2.0, 3.0}
SerializationVersion 1.1.0.1
BuildVersion 6.2.9200.16398
PSVersion 3.0
CLRVersion 4.0.30319.296
PSRemotingProtocolVersion 2.2


Your text editor showed you all lines exactly like you posted or was it only okay after pasting it in the text field of your internet browser?
by nohandle at 2012-12-10 12:25:49
The output on my station is the same as on David`s station.
by megamorf at 2012-12-10 23:43:35
When the file is invoked it looks like this is notepad for me:
a user uploaded image

I checked the output with notepad++'s "show end of line" function:
a user uploaded image

What you can see is that even though the orignal here-string consist of carriage return + line feed the strings in notepad only contain line feeds. This time I tested on WIn7 SP1 notebook with PSv2.
by nohandle at 2012-12-11 02:30:25
a user uploaded image
works for me, strange issue on your side.
edit: W7 SP1 in vmWare, Posh v2, works from console and PowerGUI