Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Dynamically adding properties to an object instance

Reply
 
Old 12-19-2006   #1 (permalink)
dan.farino@gmail.com


 
 

Dynamically adding properties to an object instance

Hi folks,

Is there a way to dynamically add properties to an object instance
similar to the way PowerShell's XML data type adds properties for
elements and attributes (e.g. $xml.RootNode.Customer.Id)? I want to do
something similar for DataSet and DataTable objects (e.g.
$ds.CustomerTable.Rows[10].FirstNameColumn).

On a similar note, is there a way to add a ScriptProperty in my
types.ps1xml file (or somewhere else) that serves as a "catch all" (so,
if I type $myobj.UnknownProperty, it will run my script and let it
return a value for that non-existent property)?

Thanks!
Dan


My System SpecsSystem Spec
Old 12-19-2006   #2 (permalink)
Gaurhoth


 
 

Re: Dynamically adding properties to an object instance

add-member cmdlet lets you add properties/scriptblocks/etc to an object
instance.

ps:> get-help add-member -full

for additional info including examples.


gaurhoth

<dan.farino@gmail.com> wrote in message
news:1166566716.960243.125530@n67g2000cwd.googlegroups.com...
> Hi folks,
>
> Is there a way to dynamically add properties to an object instance
> similar to the way PowerShell's XML data type adds properties for
> elements and attributes (e.g. $xml.RootNode.Customer.Id)? I want to do
> something similar for DataSet and DataTable objects (e.g.
> $ds.CustomerTable.Rows[10].FirstNameColumn).
>
> On a similar note, is there a way to add a ScriptProperty in my
> types.ps1xml file (or somewhere else) that serves as a "catch all" (so,
> if I type $myobj.UnknownProperty, it will run my script and let it
> return a value for that non-existent property)?
>
> Thanks!
> Dan
>


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Inherit from usercontrol - Object not set to instance of an object .NET General
datalist -- Object reference not set to an instance of an object. .NET General
False IE doc body error - "Object reference not set to an instance of an object" PowerShell
Adding canonical aliases for Compare-Object, Measure-Object, New-Object PowerShell


Vista Forums 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 Ltd

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