Return it as the function value or as a [ref] value. Not sure I understand what 
you are asking for, if that isn't what you mean...

function make-object()
{
                $obj = "" | select Company, Employee, Type, Rate, Balance, Date

                return $obj
}

This returns a PSObject with the named fields. You can do the same thing with 
New-Object and Add-Member, but the v1 syntax shown above is MUCH faster.

From: Joseph L. Casale [mailto:[email protected]]
Sent: Tuesday, April 10, 2012 7:20 PM
To: NT System Admin Issues
Subject: Creating objects within a function

How do you handle the case where you create .NET objects within a function and 
want to use them outside?
I have a block of code that I use in several places where I want to create a 
function for example.

Thanks!
jlc

~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to 
[email protected]<mailto:[email protected]>
with the body: unsubscribe ntsysadmin

~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to [email protected]
with the body: unsubscribe ntsysadmin

Reply via email to