liveBook · Manning

COM object

As explained in Practical Automation with PowerShell: Effective scripting from the console to the cloud

A COM object is a software component that exposes interfaces through Microsoft's Component Object Model for interprocess or cross-application interaction.

A COM object is an external application object that PowerShell can create and control through Microsoft's Component Object Model. This connects scripts with applications and other resources outside PowerShell, including automated document generation. section 9.0

Create a COM object with New-Object and its ProgID. The ProgID is a readable name representing an application's CLSID, while properties expose data and methods perform actions. section 9.1

A practical COM automation workflow includes:

  • Choose the application's ProgID, such as Word.Application. section 9.1 section 9.1.1
  • Create the application object and use its properties and methods to manipulate the target application. section 9.1
  • Load Microsoft Office interop assemblies when Word automation needs simplified typed interactions. section 9.1.1
  • Account for runtime differences: Windows PowerShell 5.1 can resolve the interop by name, while PowerShell 7 may require DLL paths from the GAC. section 9.1.1 section 9.6

Create a Word automation object

$Word = New-Object -ComObject Word.Application This instance can support a repeatable workflow that gathers local computer information and places it into a consistently formatted Word document. section 9.1.1 section 9.0

Figure 9.1 Write computer information to a Word document automation flow

Trace the automation flow from collecting computer information to writing the resulting document. section 9.0

How Practical Automation with PowerShell: Effective scripting from the console to the cloud covers it

How deep it goes
Explains ProgIDs, object members, Word creation, and interop loading, but stops short of detailing the full COM interface model.
Examples
Uses Word.Application to populate a Word document with local computer information and identifies Outlook.Application as another ProgID.
What it assumes
Assumes PowerShell familiarity and locally installed Microsoft Word while teaching ProgIDs and COM object creation.
What you can do after
Operate Microsoft Word through PowerShell by creating its COM object and loading required interop assemblies.
How it connects
Connects COM objects with PowerShell, New-Object, ProgIDs, CLSIDs, .NET Framework, Office interop assemblies, and the GAC.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Practical Automation with PowerShell: Effective scripting from the console to the cloud. The section links point to the parts of the book it draws on.