January 1, 2012 at 12:00 am #5489
by brittfam at 2013-01-30 15:53:27
I need help understanding how find out about methods and properties. Please read before commenting.
I am trying to create a script to obtain server inventory information. I want to output to a word template. I have searched and found a simple script that creates a doc and will add the information. What I do not understand is how the methods were discovered.
for instance the script starts with creating a new object
$word=new-object -comobject "word.application"
Then a new document object
When i type "$word | get-member" I can see "Documents" as a property.
When I type $doc | get-member i get an error.
My question is, "how would I have discovered there was a "word.application.documents.add() to create a new document. I could not discover the .documents.add() with the get-member cmdlet.
I want to know how this .add() is discovered so that I can explore more options like setting headers and fonts and spacing, colors, etc. It is not listed as a method. Although there are several other add... methods listed. This one is not. Please help so that I can go further in understanding.
by cookie.monster at 2013-01-30 18:03:37
I would recommend looking up the MSDN page for the object you are interested in. They are generally documented well enough for you to follow along or at least start experimenting.
You were on the right track. Use something like the PowerShell ISE v3 so you can see intellisense for the various properties, much easier than exploring with get-member (sorry, not sure how to directly link these):
One quick note: You are creating a com object – I know the syntax might be confusing, but word.application does not mean application is a property. So when you ran $word | get-member, you saw all the properties and methods you could work with. If you had run $word | select -ExpandProperty documents | get-member, you would see the add method : )
by brittfam at 2013-01-30 18:22:53
Thanks cookie.monster. I will try the -Expandproperty method for more discovery. I had not used that one before.
You must be logged in to reply to this topic.