Posts Tagged PowerShell

Generic Types in PowerShell

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:

$typeKey = "[System.String, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089]"
$typeValue = "[System.Web.UI.LiteralControl, System.Web, Version=, 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.


No Comments