Files
OneNoteExporter/OneNoteXmlExport.ps1
T
2026-01-22 10:49:31 +00:00

45 lines
1.1 KiB
PowerShell

# Get export folder
$folder = "C:\Users\pgeeraert\Downloads\export-onenote"
# Connect
$OneNote = New-Object -ComObject OneNote.Application
[xml]$Hierarchy = ""
$OneNote.GetHierarchy("", [Microsoft.Office.InterOp.OneNote.HierarchyScope]::hsPages, [ref]$Hierarchy)
Function ReplaceIllegal {
param ( $text )
$illegal = [string]::join('',([System.IO.Path]::GetInvalidFileNameChars())) -replace '\\','\\'
$replaced = $text -replace "[$illegal]",'_'
return $replaced
}
Write-Output $Hierarchy.Notebooks.Notebook.Roser.name
function LoopAndExport {
# Loop over each notebook
foreach ($notebook in $Hierarchy.Notebooks.Notebook ) {
$name = ReplaceIllegal -text $notebook.name
Write-Output $name
Write-Host $notebook.ID
Write-Host $notebook.InnerXml
$destinationFile = Join-Path -Path $folder -ChildPath $name".xml"
write-output $destinationFile
$notebookInnerXml = $notebook.InnerXml
$exportedXML = "<xml>$notebookInnerXml</xml>"
$exportedXML |Out-File $destinationFile
}
}
LoopAndExport