# encoding: ascii
# api: powershell
# title: Get-WordOutline
# description: adapted from code by Kiron news://msnews.microsoft.com:119/FAEC38D1-62A8-47B1-A94E-A29A2CA4FE29microsoft.com
# version: 0.1
# type: function
# license: CC0
# function: Get-WordOutline
# x-poshcode-id: 610
# x-derived-from-id: 611
# x-archived: 2008-09-29T01:25:04
#
# note: this is flaky for me, not sure how well it will work for you. updates welcome!
#
function Get-WordOutline ( $Path, [int]$MaxDepth = 9 ) {
if ( $Path -is [System.IO.FileInfo] ) { $Path = $_.FullName }
$word = New-Object -comObject word.application
$document = $wordd.documents.open( $path )
$outline = $document.paragraphs | Where-Object {
$_.outlineLevel -le $MaxDepth
} | ForEach-Object {
$n = ($_.outlineLevel - 1) * 2
' ' * $n + ($_.range.text -replace '\u000d$')
}
Write-Output $outline
$document.close( [ref]$false )
$word.quit()
}