![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Add method not accessibe from Powershell? I'm trying to learn Powershell and convert some of my existing VB automation over. Immediately I've run into a showstopper with a particular COM object that doesn't seem to expose the Add method of a member when working in Powershell. By contrast, I can easily invoke this method from VBScript. The application is Adobe InDesign. In VBScript, this works: Set myInDesign = CreateObject("InDesign.Application.CS3") Set myDocument = myInDesign.Documents.Add By contrast, in Powershell: $inDesign = new-object -COM "InDesign.Application.CS3" $inDesign.Documents.Add() gives the error: "Method invocation failed because [System.__ComObject] doesn't contain a method named 'add'." And it's true: $inDesign.Documents | get-member reveals no Add method. So: How is this Add method invokeable in VB if it's not exposed thru COM? Or, why can't Powershell see the method? |
| | #2 (permalink) |
| Guest | RE: Add method not accessibe from Powershell? try $inDesign.Documents.psbase | get-member and see if the Add method shows then. Or is there an Invoke method which could be used to process the Add method? -- Richard Siddaway Please note that all scripts are supplied "as is" and with no warranty Blog: http://richardsiddaway.spaces.live.com/ PowerShell User Group: http://www.get-psuguk.org.uk "joeOnSunset" wrote: > I'm trying to learn Powershell and convert some of my existing VB > automation over. Immediately I've run into a showstopper with a > particular COM object that doesn't seem to expose the Add method of a > member when working in Powershell. By contrast, I can easily invoke > this method from VBScript. > > The application is Adobe InDesign. > In VBScript, this works: > > Set myInDesign = CreateObject("InDesign.Application.CS3") > Set myDocument = myInDesign.Documents.Add > > By contrast, in Powershell: > > $inDesign = new-object -COM "InDesign.Application.CS3" > $inDesign.Documents.Add() > > gives the error: "Method invocation failed because > [System.__ComObject] doesn't contain a method named 'add'." > > And it's true: > $inDesign.Documents | get-member > reveals no Add method. > > So: How is this Add method invokeable in VB if it's not exposed thru > COM? Or, why can't Powershell see the method? > > |
| | #3 (permalink) |
| Guest | Re: Add method not accessibe from Powershell? Rich, The only members of that class are: TypeName: System.Management.Automation.PSMemberSet Name MemberType Definition ---- ---------- ---------- CreateObjRef Method System.Runtime.Remoting.ObjRef CreateObjRef(Type requestedType) Equals Method System.Boolean Equals(Object obj) GetHashCode Method System.Int32 GetHashCode() GetLifetimeService Method System.Object GetLifetimeService() GetType Method System.Type GetType() InitializeLifetimeService Method System.Object InitializeLifetimeService() ToString Method System.String ToString() I've noticed that there are a number of collections in this object model that have this same behavior (for example, Documents[n].Rectangles, the collection of rectangles in a given document.) In all cases: You can't get perform get-member on the collection unless there is an item already in the collection. So, for example, I must open a document in the application before get-member will work on the Documents collection. Even once there is an item in the collection, I can't access the item by indexing it. For example: $inDesign.Documents[0] errors out: Unable to index into an object of type System.__ComObject. I guess Visual Studio does a lot of obfuscating of the real complexities of these object models? I'm at a loss :-( On May 29, 4:03 am, RichS <R...@discussions.microsoft.com> wrote: > try > > $inDesign.Documents.psbase | get-member > > and see if the Add method shows then. Or is there an Invoke method which > could be used to process the Add method? > -- > Richard Siddaway > Please note that all scripts are supplied "as is" and with no warranty > Blog:http://richardsiddaway.spaces.live.com/ > PowerShell User Group:http://www.get-psuguk.org.uk > > > > "joeOnSunset" wrote: > > I'm trying to learn Powershell and convert some of my existing VB > > automation over. Immediately I've run into a showstopper with a > > particular COM object that doesn't seem to expose the Add method of a > > member when working in Powershell. By contrast, I can easily invoke > > this method from VBScript. > > > The application is Adobe InDesign. > > In VBScript, this works: > > > Set myInDesign = CreateObject("InDesign.Application.CS3") > > Set myDocument = myInDesign.Documents.Add > > > By contrast, in Powershell: > > > $inDesign = new-object -COM "InDesign.Application.CS3" > > $inDesign.Documents.Add() > > > gives the error: "Method invocation failed because > > [System.__ComObject] doesn't contain a method named 'add'." > > > And it's true: > > $inDesign.Documents | get-member > > reveals no Add method. > > > So: How is this Add method invokeable in VB if it's not exposed thru > > COM? Or, why can't Powershell see the method?- Hide quoted text - > > - Show quoted text - |
| | #4 (permalink) |
| Guest | Re: Add method not accessibe from Powershell? when you pipe to get-member you are not going to get the colleciton object, but the first item of that collection that powershell strips out.. so if you want to get the members on the actual collection, bind it to the inputobject, so there is no stripping i.e $a = @(1,2,3,4) ##this first one will take in the first object in the array, an iteger and give you the members on that.. $a |Get-Member ## this one will bind the whole object , thus an object[] array object, and give you the members on that. get-Member -inputobject $A |
| | #5 (permalink) |
| Guest | Re: Add method not accessibe from Powershell? Thanks, that's great to know. Exploring further, I still haven't been able to figure out how to add a Document to the Documents collection, or refer to existing Documents in the collection by index (Documents[0]). But I'll keep exploring. Can anyone point me to some good documentation on COM with Powershell? (That is, besides the User Guide. That I have :-) ) Thanks On May 30, 9:56 pm, klu...@xtra.co.nz wrote: > when you pipe to get-member you are not going to get the colleciton > object, but the first item of that collection that powershell strips > out.. so if you want to get the members on the actual collection, bind > it to the inputobject, so there is no stripping > > i.e > > $a = @(1,2,3,4) > ##this first one will take in the first object in the array, an iteger > and give you the members on that.. > $a |Get-Member > ## this one will bind the whole object , thus an object[] array > object, and give you the members on that. > get-Member -inputobject $A |
| |
| |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to call a static method in a .net class from powershell? | YY | PowerShell | 1 | 09-11-2007 12:51 AM |
| Powershell missing a WMI method? | Guy | PowerShell | 1 | 07-27-2007 01:32 PM |
| Invoke generic method from PowerShell | zach.blocker@gmail.com | PowerShell | 7 | 06-25-2007 02:33 PM |
| Re: IsUpper method in PowerShell? | Duncan Smith | PowerShell | 4 | 03-29-2007 04:46 AM |
| How to use HTMLDecode method in Powershell? | Vinicius Canto | PowerShell | 11 | 08-02-2006 07:13 PM |