Friday, August 14, 2009

Create System.Array in PowerShell

Some months ago I posted following question:

I am working with MFCOM (COM interface for Citrix) and one of
properties requires Array as input type...

So I tried simple code, [Array]$Schedules = @(), however to my
surprise System.Array is only base object (never realized that

# [array]$Schedules = @()
# $Schedules.GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     Object[]

If I try to assign this value to COM, it will return error message
stating that input type is not supported.

Obviously, no answers so far, just Gerd Schneider confirmed that this is an issue.

Long story short, it can be done pretty easily:

[Object[]]$Schedules = @()

Of course, you can replace Object with your own type:
[Byte[]]$Bytes = $Source.ToCharArray()

No comments: