Open XML for PowerShell users : PowerTools for Open XML

Combining PowerShell and Open XML, PowerTools for Open XML is a powerful way to do server-side document processing. By using PowerTools in you own PS scripts you can manage and generate Word and Excel documents ! PowerTools is available for a while, thanks to Eric, Bob McClellan and people at Staff Dot Net who worked hard to bring you PowerTools for Open XML v1.1.1. Recently updated is the DocumentBuilder
2.0.

Here’s the latest available cmdlets in PowerTools for Open XML :

  • Merge-OpenXmlDocument : this
    cmdlet is great, it merge multiple source documents into a new document, remove Paragraphs, move Styles and Fonts to a merged document,
  • Select-OpenXmlString : this cmdlet can split a document into multiple documents, extract text of a document and  find documents.

Among all the cmdlets available, here’s an excerpt of my favourite components/cmdlets available in PowerTools for Open XML :

  • RevisionAccepter : accept tracked changes for a word-processing document.
  • HtmlConverter : convert a word-processing document to XHTML.
  • Add-OpenXmlDocumentTOC : generate the table of content of your document.
  • Set-OpenXmlWatermark : specify a watermark to be inserted in your documents.
  • Add-OpenXmlContent : insert any content.
  • Add-OpenXmlDigitalSignature : add a digital signature to your documents.

You can find details and examples on the PowerTools content page.

To use PowerTool, you need to install the assembly before :

  • 32-bits system :

    • Install : c:\windows\Microsoft.NET\Framework\v2.0.50727\installutil.exe OpenXml.PowerTools.dll
    • Uninstall : c:\windows\Microsoft.NET\Framework\v2.0.50727\installutil.exe -u OpenXml.PowerTools.dll
  • 64-bits system :

    • Install : c:\windows\Microsoft.NET\Framework64\v2.0.50727\installutil.exe OpenXml.PowerTools.dll
    • Uninstall : c:\windows\Microsoft.NET\Framework64\v2.0.50727\installutil.exe -u OpenXml.PowerTools.dll

PowerTools for Open XML needs PowerShell v1 installed on the machine. You can find the source code on GitHub. The package contains a lot of samples code.

Happy scripting !