protected override void ProcessRecord() { foreach (var document in AllDocuments("Add-OpenXmlDocumentIndex")) { try { using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(document)) { using (WordprocessingDocument doc = streamDoc.GetWordprocessingDocument()) { IndexAccessor.Generate(doc); StyleAccessor.CreateIndexStyles(doc, stylesSourcePath, addDefaultStyles); } OutputDocument(streamDoc.GetModifiedDocument()); } } catch (Exception e) { WriteError(PowerToolsExceptionHandling.GetExceptionErrorRecord(e, document)); } } }