Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Passing array to .Net command: discrete parameters

Closed Thread
 
Thread Tools Display Modes
Old 10-06-2006   #1 (permalink)
=?Utf-8?B?TWlrZSBCcmlkZ2U=?= bridgecanada _ com>
Guest


 

Passing array to .Net command: discrete parameters

Hi-

I was trying to instantiate some .Net objects from PowerShell, and I am
confused about why this happens when I pass an array to the constructor:

PS [Scripts] > $bytes=@([System.Text.Encoding]::UTF8.GetBytes("Hello
There"))
PS [Scripts] > new-object System.IO.MemoryStream($bytes)
New-Object : Cannot find an overload for ".ctor" and the argument count: "11".
At line:1 char:11
+ new-object <<<< System.IO.MemoryStream($bytes)

I see that this will work if I do this:

PS [Scripts] > new-object System.IO.MemoryStream(,$bytes)

However, I don't understand why my byte array of length 11 is getting passed
as 11 parameters instead of as an array. Does anyone know why this happens?
Is this the correct way to do this?

Thanks!

-Mike

Old 10-06-2006   #2 (permalink)
=?Utf-8?B?TWlrZSBCcmlkZ2U=?= bridgecanada _ com>
Guest


 

RE: Passing array to .Net command: discrete parameters

Hi-

Sorry for the multiple posts. This worthless "Communities" forum site gave
me errors when I clicked "post".

-Mike



"Mike Bridge" wrote:

> Hi-
>
> I was trying to instantiate some .Net objects from PowerShell, and I am
> confused about why this happens when I pass an array to the constructor:
>
> PS [Scripts] > $bytes=@([System.Text.Encoding]::UTF8.GetBytes("Hello
> There"))
> PS [Scripts] > new-object System.IO.MemoryStream($bytes)
> New-Object : Cannot find an overload for ".ctor" and the argument count: "11".
> At line:1 char:11
> + new-object <<<< System.IO.MemoryStream($bytes)
>
> I see that this will work if I do this:
>
> PS [Scripts] > new-object System.IO.MemoryStream(,$bytes)
>
> However, I don't understand why my byte array of length 11 is getting passed
> as 11 parameters instead of as an array. Does anyone know why this happens?
> Is this the correct way to do this?
>
> Thanks!
>
> -Mike
>

Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing parameters to a cmdlet in a variable Alastair Smith PowerShell 1 02-08-2008 06:29 AM
passing [switch] parameters Jeff PowerShell 4 07-28-2007 09:17 AM
Passing parameters to a PS script Dan PowerShell 9 07-17-2007 05:05 PM
passing parameters to script (ps1) IT Staff PowerShell 1 10-19-2006 09:43 AM
Invoke-Item and passing command line parameters =?Utf-8?B?cm9ib3Q=?= PowerShell 5 07-17-2006 08:48 PM








Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50