Why does PowerShell split arguments containing hyphens and periods?
powershell, syntax
Solution
I've disassembled Microsoft.PowerShell.Utility to look at the code of `Write-Output` nothing special there, it just iterates through InputObject and passes each to a `WriteObject` method implemented by the current `ICommandRuntime`.
My guess is that the tokenizer that process the text tries to match anything starting with a `-` to a declared parameter. Failing that, it passes it through the pipeline as an item in `-InputObject`. Since a `.` cannot be a part of a variable name and therefore can't be part of a switch name it might separate it before doing the if check and when it turns out to be a parameter it doesn't join it back up with the rest of the token. You might therefore have found a minor bug.
When using the back tick or quotation marks it doesn't make this mistake however since it can tokenize the entire thing.
This is all conjecture though, I'd love to see a authoritative answer as much as you.
Edit
Evidence of what I'm saying:
PS> echo -NoEnumerate.foo
.foo
Problem
In a PowerShell window: ``` PS C:\> echo -abc.def.ghi -abc .def.ghi ``` For some reason, the combination of a hyphen and period cause Powershell to split the argument into two lines. It does not occur with without the hyphen: ``` PS C:\> echo abc.def.ghi abc.def.ghi ``` Nor does it occur when there are no periods: ``` PS C:\> echo -abcdefghi -abcdefghi ``` Through experimentation, I've found I can escape the behavior with a backtick: ``` PS C:\> echo `-abc.def.ghi -abc.def.ghi ``` But why does this occur? What fundamental part of PowerShell syntax am I not understanding?