IMHO, that the trap number 1. If you return an object from a function that is somehow enumerable (I donβt know for sure whether the IEnumerable implementation is the only case), PowerShell expands the object and returns the elements in it.
Your new list was empty, so nothing was returned. To make it work, just use this:
,[Activator]::CreateInstance($closedType)
This will create one array of elements to be expanded, and the element (general list) is assigned $a .
Additional Information
Here is a list of related questions to help you understand what is happening:
Note: you do not need to declare the title of the function as a bracket. If you need to add parameters, the function will look like this:
function test { param($myParameter, $myParameter2) }
or
function { param( [Parameter(Mandatory=true, Position=0)]$myParameter, ... again $myParameter2) ...
source share