Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

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.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Add method not accessibe from Powershell?

Closed Thread
 
Thread Tools Display Modes
Old 05-28-2007   #1 (permalink)
joeOnSunset
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?

Old 05-29-2007   #2 (permalink)
RichS
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?
>
>

Old 05-29-2007   #3 (permalink)
joeOnSunset
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 -



Old 05-30-2007   #4 (permalink)
klumsy@xtra.co.nz
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

Old 05-31-2007   #5 (permalink)
joeOnSunset
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



Closed Thread

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








Vistax64.com 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 2005-2008

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 47 48 49 50