![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
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.
br>
|
|
|||||||
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 | ||
|
Guest
Posts: n/a
|
This code creates a synthetic object.
$instance = new-object Management.Automation.PSObject Add-Member -InputObject $instance NoteProperty 'Type' $type write-host "Instance created - $type" $instance.psobject.members|write-host foreach ($member in $members) { Write-Host "Adding member '$($member.name)'" $instance.psobject.members.Add($member) } As you can see in the output below, all the members are added except the 'ToString' psScriptMethod. But I get no error if I add this very same method to this very same object, using exactly the same syntax, at the command prompt. Can anyone give me a hint why? Instance created - PFW_FileID System.String Type=PFW_FileID System.String ToString() System.Type GetType() System.Boolean Equals(Object obj) System.Int32 GetHashCode()Adding member 'LName' Adding member 'EventNumber' Adding member 'ToString' Exception calling "Add" with "1" argument(s): "A PSProperty or PSMethod object cannot be added to this collection." At C:\...\Define_Class.ps1:84 char:40 + $instance.psobject.members.Add <<<< ($member) Adding member 'Match' |
||
|
|
|
|
|
|
#2 | ||||||||||||||
|
Guest
Posts: n/a
|
On Apr 10, 7:47*am, RickB <rbiel...@xxxxxx> wrote:
Never mind. I was caching the ScriptMethods like this. Obviously there would be a native Method called ToString so my synthetic member was never being created. The native method really was a duplicate and thus the error. if ($class.$name -eq $null) { Add-Member -InputObject $class ScriptMethod $name $script} $class.$name |
||||||||||||||
|
|||||||||||||||
|
|
#3 | ||||||||||||||
|
Guest
Posts: n/a
|
and $members are defined, for example. Marco -- Microsoft MVP - Windows PowerShell http://www.microsoft.com/mvp PowerGadgets MVP http://www.powergadgets.com/mvp Blog: http://marcoshaw.blogspot.com |
||||||||||||||
|
|||||||||||||||
|
|
|
|