Unquoted tokens in argument mode involving variable references and subexpressions: why are they sometimes split into multiple arguments? Unquoted tokens in argument mode involving variable references and subexpressions: why are they sometimes split into multiple arguments? powershell powershell

Unquoted tokens in argument mode involving variable references and subexpressions: why are they sometimes split into multiple arguments?


I think what you're sort of hitting here is more the the type "hinting" than anything else.

You're using Write-Output which specifies in it's Synopsis that it

Sends the specified objects to the next command in the pipeline.

This command is designed to take in an array. When it hits the first item as a string like today/ it treats it like a string. When the first item ends up being the result of a function call, that may or may not be a string, so it starts up an array.

It's telling that if you run the same command to Write-Host (which is designed to take in a string to output) it works as you'd expect it to:

 Write-Host $(Get-Date)/today

Outputs

7/25/2018 1:30:43 PM /today

So I think you're edge cases you're running up against are less about the parsing, and mor about the typing that powershell uses (and tries to hide).