liveBook · Manning

Word object model

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

A Word COM object is a Component Object Model automation object that exposes Microsoft Word documents and application operations.

The Word object model exposes Microsoft Word documents and application operations as COM automation objects. PowerShell can use it to create a document, populate structured content, insert images, update a table of contents, and save the result. section 9.5

Implementation starts by loading the Word COM object, creating a document, and loading the Word interop assemblies. Reusable functions then separate document structure from data collection: headings, object-to-table conversion, array-to-table conversion, and time-series graph insertion. section 9.5

$Selection.Tables.psobject.methods
OverloadDefinitions
-------------------
Table Item (int Index)
Table AddOld (Range Range, int NumRows, int NumColumns)
Table Add (Range Range, int NumRows, int NumColumns, Variant
 DefaultTableBehavior, Variant AutoFitBehavior)

Inspect a Word collection through PSObject when the collection is empty or Get-Member cannot inspect it. The listing exposes Add overloads, including the range, row count, column count, and behavioral enumerators required for a table. section 9.1.4

Table creation follows a small set of implementation decisions:

  • Supply a range, row count, and column count to Tables.Add(). section 9.1.4
  • Use named WdDefaultTableBehavior and WdAutoFitBehavior enum values instead of opaque integers. section 9.1.4
  • Write content through individual cells such as $Table.Cell(1,1).Range.Text. section 9.1.4

Automated system report

A reusable report function can create a title from the computer name, add a table of contents, write operating-system, disk, and network tables, retrieve external IP data with Invoke-RestMethod, graph processor-time samples, insert the PNG with InlineShapes.AddPicture(), refresh the table of contents, and save the document. section 9.5

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

How deep it goes
Descends from COM document creation to table method signatures, enum values, cell ranges, reusable functions, and an assembled reporting workflow.
Examples
Uses table overload inspection, enum discovery, cell assignment, system-information tables, external IP data, and processor-time graphs.
What it assumes
Assumes PowerShell familiarity and teaches method discovery, Word interop assembly loading, and enum selection for underspecified COM members.
What you can do after
Build it from scratch by composing PowerShell functions that generate, populate, enhance, refresh, and save Word documents.
How it connects
Connects COM automation with PowerShell, Word interop assemblies, ranges, tables, enums, table of contents, REST requests, and performance counters.

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.