Exploring the Set-OpenXmlString CMDLET in PowerTools for Open XML 2.2

The Set-OpenXmlString cmdlet enables interesting functionality – you can do a search-and-replace of content without automating Word, and you can search-and-replace in many documents at once.  The Set-OpenXmlString can search-and-replace in both WordprocessingML documents and PresentationML documents.  The following screen-cast demonstrates Set-OpenXmlString.

One of the problems of search-and-replace is that the string that matches the search string could be broken up into multiple runs.  If you are interested in the algorithm that Set-OpenXmlString uses for searching and replacing, see Introducing TextReplacer: A New Class for PowerTools for Open XML.  While the screen-cast shows only the algorithm for WordprocessingML, the algorithm for PresentationML is nearly identical.  For a slightly different take on search-and-replace, see Search and Replace Text in an Open XML WordprocessingML Document, which shows the algorithm using XmlDocument instead of LINQ to XML and a functional programming approach.