In this particular example, you can easily get what you want by pasting them into an object property. For example, let's create an array with your three tests:
$tests = @($null,@(), @($null,$null)) function Write-Visible { param($InputObject) New-Object PSObject -Property @{ Object=$InputObject } | Out-String | Out-Host }
Of course the material is Out-String | Out-Host Out-String | Out-Host is to make sure that we do not actually output objects to the pipeline, but behave like Write-Host.
So now we can run our tests:
PS> Write-Visible $tests[0] Object ------ PS> Write-Visible $tests[1] Object ------ {} PS> Write-Visible $tests[2] Object ------ {$null, $null}
Of course, the problem is that it does not work so well for real objects, because it turns them into properties of the object, where they get the rendered "ToString ()" ... however, from above my head, I can’t think how call the rendering manner that happens there without a new object.
Jaykul
source share