$root = 'C:\Users\ben\Documents\documentation\source\' # initialize the hash $topicTitles = @{} # safely open XML files Function Get-XML ($filePath) { $fileContent = New-Object System.Xml.XmlDocument # tell it not to get the DTD $fileContent.XmlResolver = $null Try { $fileContent.Load($filePath) } Catch [system.exception] { write-host "Could not open file $filePath" } $fileContent } # list DITA files from the root Get-Childitem $root -recurse -include *.dita,*.ditamap | # ignore OT directories where {$_ -notmatch 'out' -and $_ -notmatch 'temp'} | ForEach-Object { $file = $_ $fileFull = Join-Path -path $file.directory -childpath $file.name | Resolve-Path $fileFull = [string]$fileFull $fileRel = $fileFull.Replace($root, '') $fileContent = Get-XML($fileFull) # get the topic or map title $title = $fileContent.SelectSingleNode("/*/title | /bookmap/booktitle/mainbooktitle").get_InnerText() # add a record to the hash $topicTitles.Add($fileRel, $title) } $topicTitles.GetEnumerator() | Sort-Object Name | Format-Table -Autosize | Tee-Object $root\audit.txt