I thought I would clarify this as most articles don’t simplify this to easily wrap you head around.
Add-member is what I would use to add a new member to a group of properties on an object
- I create the object
- Add a noteproperty that translate to text
- create a scriptmethod that can do things based on a scriptblock when called.
- create a scriptproperty that runs each time you call the $x object to display the results of it’s script block.
Here is the code:
$x=new-object psobject
$x| add-member -name ID – value “smithx” -membertype Noteproperty
$x| add-member -name ADlookup -value { get-aduser $x.name } -membertype scriptmethod
$x|add–member -name ADinfo -value {$x.adlookup()} -membertype Scriptproperty
if you want you can overwrite a member with the -force command.