It doesn't happen just for hashtable keys. Look at this for instance:
PS > Write-Host $x.Length$y
3 rrr
But $x.Length$y
is not a valid expression:
PS > $x.Length$y
Unexpected token 'y' in expression or statement.
At line:1 char:11
+ $x.Length$y <<<<
So what must be happening is that powershell is interpreting $x.Length$y
as two separate expressions before passing them to Write-Host, and since there are two of them, Write-Host separates them with a separator.
So what is happening here then?:
PS > Write-Host $x$y
qqqrrr
$x$y
isn't a valid expression either:
PS > $x$y
Unexpected token 'y' in expression or statement.
At line:1 char:4
+ $x$y <<<<
However, with double quotes it is a valid string:
PS > "$x$y"
qqqrrr
Powershell must be converting $x$y
to a string before passing it to Write-Host as a single argument.
Basically however that is all just guesswork. It sounds plausible to me. The short answer is that you can concatenate your strings together yourself to get rid of the space:
Write-Host ($_.Key + $x)