1$app = New-Object -ComObject OneNote.Application
2$notebook = ''
3$app.OpenHierarchy('C:\one-tests\runs\capture\notebook', '', [ref]$notebook, 0)
4$section = ''
5$app.OpenHierarchy('synthetic.one', $notebook, [ref]$section, 0)
6$hierarchy = ''
7$deadline = [DateTime]::UtcNow.AddSeconds(30)
8do {
9 $app.GetHierarchy($section, 4, [ref]$hierarchy, 1)
10 [xml]$tree = $hierarchy
11 $pages = @($tree.SelectNodes('//*[local-name()="Page"]'))
12 if ($pages.Count -eq 17) { break }
13 Start-Sleep -Milliseconds 200
14} while ([DateTime]::UtcNow -lt $deadline)
15Write-Output ('pages=' + $pages.Count)
16Write-Output $hierarchy
17foreach ($page in $tree.SelectNodes('//*[local-name()="Page"]')) {
18 $content = ''
19 $app.GetPageContent($page.GetAttribute('ID'), [ref]$content, 0, 1)
20 [xml]$xml = $content
21 $texts = @($xml.SelectNodes('//*[local-name()="Outline"]//*[local-name()="T"]') | ForEach-Object { $_.InnerText })
22 @{ name=$page.GetAttribute('name'); texts=$texts; tags=@($xml.SelectNodes('//*[local-name()="Tag"]')).Count; lists=@($xml.SelectNodes('//*[local-name()="List"]')).Count } | ConvertTo-Json -Compress
23}
24$app.CloseNotebook($notebook, $false)