Posts Tagged PowerShell
Generic Types in PowerShell
Posted by Jocelyn in PowerShell on November 24, 2011
I’ve encountered a problem recently in PowerShell. I wanted to use a method which asked for a type with generic types as a parameter. I’ve tried a couple of things with no luck. After a quick search, I’ve found this discussion which lead me to my answer. Here’s an example on how to use generic types in PowerShell:
1 2 3 | $typeKey = "[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]" $typeValue = "[System.Web.UI.LiteralControl, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]" $list = New-Object "System.Collections.Generic.Dictionary``2[$typeKey, $typeValue]" |
I agree, this is a hassle, and not quite intuitive to provide the full assembly name for each generic type. I hope the team behind PowerShell will think of something more easy to work with.