*** WARNING! ***
*** This Blog Post will talk about Developer Terms ***
*** ItPros are cautioned to break out their (Patent Pending) ***
*** “Peril Sensitive Sunglasses” (Ala the HitchHikers’ Guide to the Galaxy) ***
*** Before Reading further. If you are amongst the Bold and the DARING and the ***
*** Truly Devil May Care of ITPros, Please feel free to Read on and live Daring! ***
But don’t say I didn’t warn you 🙂
Sean – The Energized Tech
Ok there may not truly be any Fun or Profit today here. I thought it was a catchy title that would probably trigger every Spam filter across the planet.
Actually no, I lied, there is a little fun involved and some Discovery You will profit too; in an increased level of knowledge.
So I wasn’t COMPLETELY lying with the title.
So in Powershell we can access various COMObjects in the system. I’m not going to try and cross into DEEP DEEP stuff about COMObjects. To be quite honest I don’t 100% understand WHAT they are but I do understand this.
It is a way to DIRECTLY interface with many applications and Systems within Windows. Let’s take an example. A Word Document.
As Morpheus would say “In the Real World Neo we start up Word, Hit File Open, and work with the documents…”
Using COMObjects we can talk DIRECTLY to Microsoft Word.
To do this we use the NEW-OBJECT Commandlet and specify the name of the Object. Now to find the COMObject name can take a little digging but there is an Easy Cheat. They’re all stored in the Registry! (Sshhhhhhh! Don’t tell!)
Many are sitting right there under HKEY_CLASSES_ROOT but I wouldn’t recommend going that route. You’ll be sitting there all day long mining the Registry (which COULD be fun if there was gold in there) What you CAN do is search for keys called “.application”
These are not the ONLY ComObjects you can use, but it’s a start. So searching under HKLM\Software\Classes and doing a find for “.application” only searching for “KEYS” (So clear off the boxes with Values and Data)
First one I encountered on my computer with Office 2007 was “Access.Application”
This suggests it PROBABLY has something to do with Microsoft Access (This is a guess, but if you dig into the values of this key you’ll see it has a default description of “Microsoft Office Access Application”
So if I want to programatically Access “Access” (or there was a play on words!) I execute this command
$MYACCESSPROGRAM=NEW-OBJECT –COMOBJECT Access.Application
You might even find it launches because you DID after all just call up an Launch access in the process.
Here’s where the fun starts. Take out the magic Period “.”, tack it onto the end of $MYACCESSPROGRAM in Powershell and start hitting Tab. You’ll see some quasi familiar features there.
Run $MYACCESSPROGRAM through GET-MEMBER
$MYACCESSPROGRAM | GET-MEMBER
You’ll see the screen fill with a plethora of goodies. Those are all Properties and Methods attached to the Access application that you can access DIRECTLY from a Powershell script (Providing of course the destination computer has Access of course)
This is different for every program. Some don’t have COM+ ability but many do. It is all thoroughly documented online as MSDN.COM for each one. But sometimes if you just play, you might be able to figure out the pieces since the naming structure DOES actually make sense.
I’ll leave this one in your hands. It’s really interesting to see just what you can access from Powershell at this point.
Powershell, cleaning up your Office for you.
The Energized Tech