Powershell . Declare generic list with class defined using 'Add-Type'
This is a bug in New-Object. This will help you create them more easily: http://www.leeholmes.com/blog/2006/08/18/creating-generic-types-in-powershell
UPDATE: PowerShell added support for this in Version 2:
PS > $r = New-Object "System.Collections.Generic.List[Int]"PS > $r.Add(10)
Well, I was trying to create a list of FileStream
objects and this was my solution (based on this link -- which actually describes a way to solve your problem):
$fs = New-Object 'System.Collections.Generic.List[System.IO.FileStream]'$sw = New-Object 'System.Collections.Generic.List[System.IO.StreamWriter]'$i = 0while ($i < 10){ $fsTemp = New-Object System.IO.FileStream("$newFileName",[System.IO.FileMode]'OpenOrCreate',[System.IO.FileAccess]'Write') $fs.Add($fsTemp) $swTemp = New-Object System.IO.StreamWriter($fsTemp) $sw.Add($swTemp) $i++}
Hope that helps!