So if one invocation of your commandlet only calls `WriteObject` once and the other calls it twice, the shell in the first case doesn't have the knowledge that it should've wrapped that one output in an array too. And it can't always wrap commandlet outputs in arrays because that would be disruptive for commandlets that semantically only have one result and so always write only one output (like `Get-Date`).
And for whatever reason, they didn't want to complicate the API to let commandlets themselves be able to express whether they'll semantically write only one output or multiple, regardless of how many times they actually call `WriteObject`. Such an API can't be a static attribute on the commandlet because commandlets can have wildly varying output based on their parameters. It can't be an overload of `WriteObject` like `(Object, bool iMightWriteMoreValues)` because it has to work for empty arrays. So it would have to be a separate `IWillWriteMultipleValues()` function probably.
Edit: Also explained here: https://news.ycombinator.com/item?id=40874873
$Ary = @(, "value")
One cool feature for creating arrays (especially larger arrays, for performance improvements over using +=) is to assign your array to a for loop. It wasn’t an obvious method of populating an array to me, but is definitely handy. $Ary = foreach ($Obj in $Objs) { @{ foo = $Obj.foo } }I use
[array]$Ary = "value"That sounds like a classic case of software trying to be "too clever," nine times out of ten of which will invariably backfire.
As a software developer, one should always resist the temptation to make their software "too clever."
A scalar however is not a tuple of length 1