PowerShell function won't return object

Posted by Dan on Stack Overflow See other posts from Stack Overflow or by Dan
Published on 2010-06-02T19:46:14Z Indexed on 2010/06/02 20:14 UTC
Read the original article Hit count: 152

Filed under:
|
|

I have a simple function that creates a generic List:

function test()
{
    $genericType = [Type] "System.Collections.Generic.List``1"
    [type[]] $typedParameters = ,"System.String"
    $closedType = $genericType.MakeGenericType($typedParameters)
    [Activator]::CreateInstance($closedType)
}

$a = test

The problem is that $a is always null no matter what I try. If I execute the same code outside of the function it works properly.

Thoughts?

© Stack Overflow or respective owner

Related posts about powershell

Related posts about object