Thomas Lee
2007-03-04 15:39:23 UTC
I'm trying to illustrate the use of the .Net random number class
(system.random). It contains a method "NextBytes" with the Definition of
System.Void NextBytes(Byte[] buffer) but I can't work out how to call it
to generate a random string.
How do you create a byte array for use with this class using PowerShell?
In C# it's easy:
Random randObj = new Random();
Byte[] randArray = new Byte[20];randObj.NextBytes(randArray);
But I can not replicate this code in PowerShell. I've tried obvious:
PSH [D:\foo]: $str=new-object [byte[]]
New-Object : Cannot find type [[byte[]]]: make sure the assembly
containing this type is loaded.
At line:1 char:16
+ $str=new-object <<<< [byte[]]
PSH [D:\foo]: $str=new-object byte[]
New-Object : Constructor not found. Cannot find an appropriate
constructor for type byte[].
At line:1 char:16
+ $str=new-object <<<< byte[]
I know I'm probably missing some thing pretty vital in terms of
transferring my limited C# knowledge to PowerShell.
Any Clues??
This is driving me nuts!!
Thomas
(system.random). It contains a method "NextBytes" with the Definition of
System.Void NextBytes(Byte[] buffer) but I can't work out how to call it
to generate a random string.
How do you create a byte array for use with this class using PowerShell?
In C# it's easy:
Random randObj = new Random();
Byte[] randArray = new Byte[20];randObj.NextBytes(randArray);
But I can not replicate this code in PowerShell. I've tried obvious:
PSH [D:\foo]: $str=new-object [byte[]]
New-Object : Cannot find type [[byte[]]]: make sure the assembly
containing this type is loaded.
At line:1 char:16
+ $str=new-object <<<< [byte[]]
PSH [D:\foo]: $str=new-object byte[]
New-Object : Constructor not found. Cannot find an appropriate
constructor for type byte[].
At line:1 char:16
+ $str=new-object <<<< byte[]
I know I'm probably missing some thing pretty vital in terms of
transferring my limited C# knowledge to PowerShell.
Any Clues??
This is driving me nuts!!
Thomas
--
Thomas Lee
***@gmail.com
MVP - Admin Frameworks and Security
Thomas Lee
***@gmail.com
MVP - Admin Frameworks and Security