I'm trying to make a PowerShell script using the DocumentFormat.OpenXml library. Everything is working fairly well, except that I'm struggling with syntax for passing type parameters. Specifically, I'm working with the DocumentFormat.OpenXml.OpenXmlElement.Descendants
method. I can easily call it like this:
using assembly /root/.nuget/packages/documentformat.openxml/2.17.1/lib/net40/DocumentFormat.OpenXml.dll;
using namespace DocumentFormat.OpenXml;
$Output = Resolve-Path "$(Get-Location)\out.docx"
$myDoc = [WordprocessingDocument]::Open($Output, $true)
$mainPart.Document.Body.Descendants()
This returns all of the descendants. However, I'd really like to call $mainPart.Document.Body.Descendants<FormFieldData>()
to get only descendants of that type. Unfortunately, PowerShell doesn't like the <>
syntax. It gives me this message:
At line:1 char:36
+ $mainPart.Document.Body.Descendants<FormFieldData>()
+ ~
The '<' operator is reserved for future use.
I'm sure this is simply a matter of not knowing the correct PowerShell syntax, but my Google skills are failing me and I can't seem to find the correct syntax.