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

Using dynamic type as function parameter

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 05-05-2007   #1 (permalink)
Jonathan
Guest


 

Using dynamic type as function parameter

I'm having an issue using a dynamic type as a function parameter in a script
file.

I dynamically define and create the enum first, and then attempt to define
a function with the enum type as a parameter. For example:

New-Enum "MyType" Red Blue Green
#(from
http://blogs.msdn.com/powershell/arc...owershell.aspx )

function MyFunction ([string] $param1, [MyType] $param2) {}

If this code is in a script file, I get the error "Unable to find type
[MyType]: make sure that the assembly containing this type is loaded."

If I define the type at the command line, then execute the script, it's fine.

Additionally, I've found if I redefine the function like:

function MyFunction ([string] $param1, $param2 = [MyType]::Red) {}

I don't get errors when executing the script. However, I lose the strong
type of the variable.

Any suggestions for how I can keep the custom types on the parameter?

My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing dynamic number of parameters to a function as a variable Robin Moffatt PowerShell 10 01-30-2008 12:38 AM
Function Parameter passing wrong or am I ? joergH PowerShell 4 01-23-2007 05:16 PM
Return type from function (Is it an egg or a chicken?) rockmoose PowerShell 3 12-21-2006 04:41 AM
function: Showing valid parameter values for a set Alex K. Angelopoulos [MVP] PowerShell 0 07-05-2006 07:50 AM
Suggestion: New Parameter Type - PSProviderPath/PSProviderRoot (PsPath/PsRoot) Alex K. Angelopoulos [MVP] PowerShell 4 07-02-2006 04:34 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 51