Note: This is ultimately another manifestation of #5579.
-f, when passed an array that is invisibly [psobject]-wrapped, fails to recognize the array as such.
This can happen with arrays returned as a whole from cmdlets, such as with Write-Output -NoEnumerate and Get-Content -ReadCount.
Simplest, but contrived repro: '{0} {1}' -f ([psobject] (1, 2))
Note:
Steps to reproduce
# Create two 2-element arrays: one with an expression, another via a cmdlet.
$arr1 = 1, 2
$arr2 = Write-Output -NoEnumerate 1, 2
'{0} {1}' -f $arr1 | Should -Be '1 2'
'{0} {1}' -f $arr2 | Should -Be '1 2'
Expected behavior
Both tests should succeed.
Actual behavior
The 2nd test fails, because $arr2 is (invisibly) [psobject]-wrapped.
InvalidOperation: Error formatting a string: Index (zero based) must be greater than or equal to zero and less than the size of the argument list..
Environment data
PowerShell Core 7.2.0-preview.1
Note: This is ultimately another manifestation of #5579.
-f, when passed an array that is invisibly[psobject]-wrapped, fails to recognize the array as such.This can happen with arrays returned as a whole from cmdlets, such as with
Write-Output -NoEnumerateandGet-Content -ReadCount.Simplest, but contrived repro:
'{0} {1}' -f ([psobject] (1, 2))Note:
[psobject]wrapping does not occur with arrays; it does, however, occur with scalar barewords that can be parsed as numbers, and then causes a similar problem: A "hybrid" bareword command argument that is parsed as a number unexpectedly behaves like a string with -f (format operator) #17199Steps to reproduce
Expected behavior
Both tests should succeed.
Actual behavior
The 2nd test fails, because
$arr2is (invisibly)[psobject]-wrapped.Environment data