Last active
May 27, 2023 06:39
-
-
Save espio999/cd54884cf75c53b06f53b687b95925e4 to your computer and use it in GitHub Desktop.
Print OneNote structure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function printAll($hierarchy, $indent_level){ | |
foreach ($item in $hierarchy.ChildNodes){ | |
printName $item $indent_level $False | |
} | |
} | |
function printName($items, [int]$indent_level, [bool]$printID){ | |
$indent = "`t" * $indent_level | |
foreach($item in $items){ | |
if ($printID){ | |
$item_id = "`t" + $item.ID | |
} | |
else{ | |
$item_id = "" | |
} | |
Write-Host ($indent + $item.name + $item_id) | |
if ($item.HasChildNodes){ | |
$node_depth = countNodeDepth $indent_level | |
printAll $item $node_depth | |
} | |
} | |
} | |
function countNodeDepth([int]$n){ | |
return $n + 1 | |
} | |
$OneNote = New-Object -ComObject OneNote.Application | |
Add-Type -assembly Microsoft.Office.Interop.OneNote | |
$OneNoteID = "" | |
[xml]$Hierarchy = "" | |
$OneNote.GetHierarchy( | |
$OneNoteID, | |
[Microsoft.Office.InterOp.OneNote.HierarchyScope]::hsPages, | |
[ref]$Hierarchy, | |
[Microsoft.Office.InterOp.OneNote.XMLSchema]::xsCurrent) | |
printAll $Hierarchy 0 | |
[System.Runtime.InteropServices.Marshal]::ReleaseComObject($OneNote) | Out-Null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment