Skip to content

Instantly share code, notes, and snippets.

@espio999
Created May 27, 2023 07:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save espio999/93fd5777804176ed38d0c91caee8222c to your computer and use it in GitHub Desktop.
Save espio999/93fd5777804176ed38d0c91caee8222c to your computer and use it in GitHub Desktop.
Export OneNote item as docx file and convert it to markdown with pandoc
$OneNote = New-Object -ComObject OneNote.Application
Add-Type -assembly Microsoft.Office.Interop.OneNote
$target_id = "{A969C2B3-B790-0EDD-2E5A-9D834611888C}{1}{E1950583228671326940781911959017434812881141}"
$publish_path = "G:\work\onenote\export.docx"
$pandoc_path = "p:\myapp\pandoc-3.1.2"
$markdown_path = "G:\work\onenote\export.md"
$OneNote.Publish(
$target_id,
$publish_path,
[Microsoft.Office.InterOp.OneNote.PublishFormat]::pfWord,
"")
[System.Runtime.InteropServices.Marshal]::ReleaseComObject($OneNote) | Out-Null
cd $pandoc_path
.\pandoc.exe --from=docx --to=markdown -o $markdown_path $publish_path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment