Thursday, April 09, 2009

PowerShell, OpenXML, WMI and the PowerTools for OpenXML = Doc generation for our inner geek - Generating a document using PowerTools for Open XML and PowerShell

“In this article I have a go at creating an Open XML Document using Microsoft’s excellent PowerShell command-line environment. To do so I use PowerTools for Open XML, recently updated on CodePlex (

As you’ll see it makes an otherwise difficult task really quite easy.

The scenario

To demonstrate this I’ve come up with what I think might be a reasonably real-world scenario. If not, hopefully it’s enough to get the concept across.

The scenario I chose is one of an SLA (service level agreement) type report. Imagine you’re a company providing an agreed level of service on servers for various clients. It’s quite likely you’d want to send your client details on how well you are fulfilling the SLA.

Here are the basic requirements for this report:

  • Create a PowerShell script that can be run for a specified client and computer name, and produces a single Word document.

  • The beginning of the output document will be tailored for the particular client.

  • The middle will be built up from 1 or more SLA metrics, using WMI information.

    • For simplicity’s sake I’m going to use simple WMI metrics for Processor Time % and Disk Time %

    • Depending on these metrics the appropriate Pass/Fail content will be output.

  • The end will be standard for all clients.

Getting Started

All going well you should end up with an output.docx file in the current directory looking like this...



Thanks to the PowerTools for Open XML we have a simple, but powerful way of building up a document using PowerShell.

PowerShell is very powerful in its own right, but I do believe it would have been a fairly painful to achieve this result without the PowerTools for Open XML.


For whatever reason I find OpenXML doc gen via PowerShell weirdly attractive (like a moth to flame? ;)

(via US ISV Developer Evangelism Team - Generate a Server-side Documents Using PowerTools for OpenXML)


Related Past Post XRef:
Because it’s a PowerShell kind of day… PowerTools for Open XML V1.1 Released
OpenXML PowerTools updated – Cell your Excel via PowerShell
Powering into OpenXML with PowerShell

No comments: