Git Product home page Git Product logo

convertonenote2markdown's Introduction

title author date last_modified_at keywords abstract permalink
Convert OneNote to MarkDown
Sjoerd de Valk, SPdeValk Consultancy
2019-05-19 15:35:00 -0700
2022-12-01 00:41:58 +0200
migration
tooling
onenote
markdown
powershell
This document is about converting your OneNote data to Markdown format.
/index.html

GitHub License Hits GitHub All Stars GitHub All Forks GitHub Latest Release GitHub All Downloads

Convert OneNote to MarkDown

Summary

!!! question Ready to make the step to Markdown and saying farewell to your OneNote, EverNote or whatever proprietary note taking tool you are using? Nothing beats clear text, right? Read on!

The PowerShell script 'ConvertOneNote2MarkDown.ps1' will utilize the OneNote Object Model on your workstation to convert all OneNote pages to Word documents and then utilizes PanDoc to convert the Word documents to Markdown (.md) format. It will also:

  • Create a folder structure for your Notebooks and Sections
  • Append prefixes to page filenames if they were indented beneath other pages (so called 'page levels')
  • Extract all Images to the '/media' folder of each section and fix references in the resulting .md files
  • Extract all File Objects to the same folder as where the page is in and fix references in the resulting .md files
  • Cleanup intermediate Word files

Known Issues

  1. Password protected sections should be unlocked before continuing, the Object Model does not have access to them if you don't
  2. Section Groups on the first level are listed but are ignored. Nested Section Groups are not processed at all.
    • Recommendation: if you make heavy use of (Nested) Section Groups you first have to reorganize in a way that they are out of the picture. Usually creating a new Notebook named the same as your Section Group and moving all relevant Sections.
  3. You should start by 'flattening' all pen/hand written elements in your OneNote pages. Because OneNote does not have this function you will have to take screenshots of your pages with pen/hand written notes and paste the resulting image and then remove the scribblings. If you are a heavy 'pen' user this is a very cumbersome. If you have an automated solution for this, please let me know
  4. Relative paths can not be used as input for the target folder. Always use an absolute path (ex. 'c:\temp\notes').
  5. This script uses only absolute paths internally, mainly because pandoc on Windows has trouble processing relative paths and for consistency. This will not be changed.
  6. While running the conversion OneNote will be unusable and it is recommended to 'walk away' and have some coffee as the Object Model might be interrupted if you do anything else.
  7. Linked file object in .md files are clickable in VSCode, but do not open in their associated program, you will have to open the files directly from the file system.
  8. Anything I did not catch... please submit an issue.

Requirements

  • Windows >= 10

    • I have only tested this on Windows...
  • Windows PowerShell 5.1

  • Microsoft OneNote >= 2016

  • Microsoft Word >= 2016

  • PanDoc >= 2.7.2

    • TIP: Use Chocolatey to install this on Windows, this will also set the right path (environment) statements

Installation

Clone this repository to acquire the PowerShell script.

Usage

  1. Start the OneNote application. All notebooks currently loaded in OneNote will be converted

  2. Open a PowerShell terminal and navigate to the folder containing the script and run it:

    '.\ConvertOneNote2MarkDown.ps1'
  3. It will ask you for the path to store the markdown folder structure. Please use an empty folder.

    Attention: use a full absolute path for the destination

  4. Sit back and wait until the process completes

Results

The script will log any errors encountered at the end of its run, so please review, fix and run again if needed. If you are satisfied check the results with a markdown editor like VSCode. All images should popup just right in the Preview Pane for Markdown files.

Recommendations

  1. I would like to recommend this repository VSCodeNotebook to host your resulting Markdown Notes folder structure. This solution supports encrypting sensitive (markdown) files and works quite nicely.

  2. While working with markdown in VSCode these are the extensions I like using:

        .\code `
        --install-extension davidanson.vscode-markdownlint `
        --install-extension ms-vscode.powershell-preview `
        --install-extension jebbs.markdown-extended `
        --install-extension telesoho.vscode-markdown-paste-image `
        --install-extension redhat.vscode-yaml `
        --install-extension vscode-icons-team.vscode-icons `
        --install-extension ms-vsts.team

    NOTE: The bottom three are not really markdown related but are quite obvious.

  3. Interesting forks have been developed you might want to take a look at. Especially the one for an Obsidian target made by @rab-bit.

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

[Unreleased]

[1.0.0] - 2019-05-19

Added
  • Initial Release
Changed
  • Nothing
Removed
  • Nothing

Credits

convertonenote2markdown's People

Contributors

sjoerdv avatar wolfteeth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

convertonenote2markdown's Issues

Exception calling "GetHierarchy" with "3" argument(s)

Exception calling "GetHierarchy" with "3" argument(s): "Unable to cast COM object of type
'Microsoft.Office.Interop.OneNote.Application2Class' to interface type
'Microsoft.Office.Interop.OneNote.IApplicationCOM'. This operation failed because the QueryInterface call on the COM
component for the interface with IID '{452AC71A-B655-4967-A208-A4CC39DD7949}' failed due to the following error:
Interface not registered (Exception from HRESULT: 0x80040155)."
At C:\OneNote2MarkDown\ConvertOneNote2MarkDown-master\ConvertOneNote2MarkDown.ps1:21 char:3
+   $OneNote.GetHierarchy("", [Microsoft.Office.InterOp.OneNote.Hierarc ...
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : InvalidCastException

Windows 10 on a Surface Pro 6
Office Professional Plus 2019

Error running script. Com class retreival.

New-Object : Retrieving the COM class factory for component with CLSID {00000000-0000-0000-0000-000000000000} failed
due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
At F:\Downloads\ConvertOneNote2MarkDown-master\ConvertOneNote2MarkDown.ps1:47 char:14

  • $OneNote = New-Object -ComObject OneNote.Application
  •          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : ResourceUnavailable: (:) [New-Object], COMException
    • FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand

Unable to find type [Microsoft.Office.InterOp.OneNote.HierarchyScope].
At F:\Downloads\ConvertOneNote2MarkDown-master\ConvertOneNote2MarkDown.ps1:50 char:29

  • ... erarchy("", [Microsoft.Office.InterOp.OneNote.HierarchyScope]::hsPage ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (Microsoft.Offic....HierarchyScope:TypeName) [], RuntimeException
    • FullyQualifiedErrorId : TypeNotFound

Exception calling "ReleaseComObject" with "1" argument(s): "Object reference not set to an instance of an object."
At F:\Downloads\ConvertOneNote2MarkDown-master\ConvertOneNote2MarkDown.ps1:248 char:3

  • [System.Runtime.Interopservices.Marshal]::ReleaseComObject($OneNote ...
  • + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : NullReferenceException
    
    

Remove-Variable : Cannot find a variable with the name 'OneNote'.
At F:\Downloads\ConvertOneNote2MarkDown-master\ConvertOneNote2MarkDown.ps1:249 char:3

  • Remove-Variable OneNote
  • + CategoryInfo          : ObjectNotFound: (OneNote:String) [Remove-Variable], ItemNotFoundException
    + FullyQualifiedErrorId : VariableNotFound,Microsoft.PowerShell.Commands.RemoveVariableCommand
    

If utf-8 string in some markdown file has broken, need to specify UTF8

If utf-8 string in some markdown file has broken, need to specify UTF8 encoding to Get-Content and Set-Content pairs

like from

((Get-Content -LiteralPath "$($fullexportpathwithoutextension).md" -Raw).Replace("$($pageinsertedfile.InsertedFile.preferredName)", "[$($destfilename)](./$($destfilename))")) | Set-Content -LiteralPath "$($fullexportpathwithoutextension).md"

to

((Get-Content -LiteralPath "$($fullexportpathwithoutextension).md" -Raw -Encoding UTF8).Replace("$($pageinsertedfile.InsertedFile.preferredName)", "[$($destfilename)](./$($destfilename))")) | Set-Content -LiteralPath "$($fullexportpathwithoutextension).md" -Encoding UTF8

.

Repeate all Get-Content and Set-Content pair (current version has 4 pairs)

subpages with identical names but in different parents overwrite each other

Problem

OneNote subpages are not correctly handled in the scenario with two subpages with the same name but belonging to different parents. The created word documents have the same name, hence the latter one overwrites the earlier one.

Example

  • Parentpage01
    • SubpageA
  • Parentpage02
    • SubpageA

This will result in a single SubpageA.docx word document, where the latter one has overwritten the earlier one.

Fix

I think the bug would be fixed by adding the second statement

$fullexportpathwithoutextension = "$($fullexportdirpath)\$($pagename)"
$fullexportpath = "$($fullexportpathwithoutextension).docx"

after https://github.com/SjoerdV/ConvertOneNote2MarkDown/blob/master/ConvertOneNote2MarkDown.ps1#L118

so that the line

$OneNote.Publish($pageid, $fullexportpath, "pfWord", "")

in https://github.com/SjoerdV/ConvertOneNote2MarkDown/blob/master/ConvertOneNote2MarkDown.ps1#L122

actually uses the correct and unique name including the pagename.

also the earlier check in
https://github.com/SjoerdV/ConvertOneNote2MarkDown/blob/master/ConvertOneNote2MarkDown.ps1#L65
should be moved lower into line 120 to check the actual word file path.

Unexpected token ':"en"' in expression or statement.

Getting this error when running the script.

Line |
  40 |  … script type="application/json" id="client-env">{"locale":"en","featur …
     |                                                            ~~~~~
     | Unexpected token ':"en"' in expression or statement.

Am I doing something wrong?

Class not registered

Not sure what the problem is:

Class not registered
"
at Publish-OneNotePage, C:\users\coffeegrindsWindows\Downloads\ConvertOneNote2MarkDown-master\ConvertOneNote2MarkDown-v2.ps1: line 628
at Convert-OneNotePage<Process>, C:\users\coffeegrindsWindows\Downloads\ConvertOneNote2MarkDown-master\ConvertOneNote2MarkDown-v2.ps1: line 1135
at New-SectionGroupConversionConfig, C:\users\coffeegrindsWindows\Downloads\ConvertOneNote2MarkDown-master\ConvertOneNote2MarkDown-v2.ps1: line 1025
at Convert-OneNote2MarkDown, C:\users\coffeegrindsWindows\Downloads\ConvertOneNote2MarkDown-master\ConvertOneNote2MarkDown-v2.ps1: line 1435
at <ScriptBlock>, C:\users\coffeegrindsWindows\Downloads\ConvertOneNote2MarkDown-master\ConvertOneNote2MarkDown-v2.ps1: line 1471
at <ScriptBlock>, <No file>: line 1
Failed to publish page to docx file C:\users\coffeegrindsWindows\Downloads\converted-onenote\PERSONAL\docx\New-House-Neighbors.docx
Failed to convert page: New-House\Neighbors
Exception calling "Publish" with "4" argument(s): "Class not registered

Class not registered

Unable to find type [Microsoft.Office.InterOp.OneNote.HierarchyScope

G'day,

I am running latest Windows 11 and Microsoft® OneNote® for Microsoft 365 MSO (Version 2405 Build 16.0.17628.20006) 64-bit and when I run this script, all I see is the following error:

InvalidOperation: C:\Users\User.Name\Downloads\ConvertOneNote2MarkDown\ConvertOneNote2MarkDown.ps1:50
Line |
50 | … erarchy("", [Microsoft.Office.InterOp.OneNote.HierarchyScope]::hsPage …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Unable to find type [Microsoft.Office.InterOp.OneNote.HierarchyScope].
0

Converter is adding ">" before all bullets, as well as extra lines

Thanks again for making this. Its a major improvement over my previous workflow of Onenote->Evernote-> Notion or Joplin. Though I've found what I consider to be a couple bugs and I hope you can help!

Here's a few screenshots.
Original:
image

After search and replace for "> ", to get rid of the quote blocks:
image

After removing extra lines:

image

The search and replace isn't a huge deal, though it becomes a trickier regex job when there are links and other formatting in the Onenote that use < >.

The extra lines are much more of a nuisance as it messes up the formatting of the bullet lists.

Anything that can be done about this?

Error while publishing file 'xxx' to docx: Exception calling "Publish" with "4" argument(s): "Exception from HRESULT: 0x8004201A"

(probably the same as #15 )

It crashes on a specific file that has (in onenote) 2 entries with the same name in the same section

Error while publishing file 'something_specific' to docx: Exception calling "Publish" with "4" argument(s): "Exception from HRESULT: 0x8004201A"

There are 2 md files, one with a _1, but the contents is identical which is not correct but this is because probably it continues after the catch. There is 1 word doc. I think the first one succeeds and then the second one somehow fails.

So the 2nd word document is raising the exception. I will place some more debug lines since in theory the word doc should be deleted at the end of the "for each page", so a new one, with a different page id can be written.

Subfolders rather than appending a prefix for subpages?

I very much appreciate your treatment of subpages in relation to their parents - I'm pretty sure my other two solutions of Evernote->Joplin/Notion don't do this and you end up with a mass of unsorted pages.

But, while the prefixes keep them all in order in the file explorer, I will inevitably be renaming them to their original name after organizing/linking them. So, I'm wondering if subfolders could be created, which I can then drag files out of once they have been appropriately treated?

I can see where you handle this in the code, but it's far beyond me to change it.

Thanks!

More conversion errors

I'm running the script as Admin in Powershell ISE also Onenote as Admin (version 16.0.14430.20270).

First few notes seem to convert OK but with warnings:

pandoc.exe : [WARNING] Deprecated: --atx-headers. Use --markdown-headings=atx instead.
At C:\Users\G\Downloads\1convert\master\ConvertOneNote2MarkDown.ps1:132 char:17
+ ...             pandoc.exe -f docx -t gfm -i $fullexportpath -o "$($fulle ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: ([WARNING] Depre...gs=atx instead.:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

Then the trouble really starts, all the following notes go something like this:

Error while publishing file 'Note Title' to docx: Exception calling "Publish" with "4" argument(s): "The remote p
rocedure call failed. (Exception from HRESULT: 0x800706BE)"
pandoc.exe : [WARNING] Deprecated: --atx-headers. Use --markdown-headings=atx instead.
At C:\Users\G\Downloads\1convert\master\ConvertOneNote2MarkDown.ps1:132 char:17
+ ...             pandoc.exe -f docx -t gfm -i $fullexportpath -o "$($fulle ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: ([WARNING] Depre...gs=atx instead.:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 
couldn't unpack docx container: not enough bytes
Exception calling "GetPageContent" with "3" argument(s): "The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)"
At C:\Users\G\Downloads\1convert\master\ConvertOneNote2MarkDown.ps1:141 char:15
+               $OneNote.GetPageContent($pageid, [ref]$pagexml, 7)
+               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : COMException
 
Get-Content : Cannot find path 'C:\Users\G\Downloads\1convert\structure\FH\FH\Note Title.md' because it does 
not exist.
At C:\Users\G\Downloads\1convert\master\ConvertOneNote2MarkDown.ps1:192 char:19
+ ...           ((Get-Content -LiteralPath "$($fullexportpathwithoutextensi ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\G\Down...Note Title.md:String) [Get-Content], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand
 
Error while renaming image file path references for file 'Note Title': You cannot call a method on a null-valued 
expression.

Suggestions please ...

implicit type conversion not possible (Application2Class => IApplicationCOM)

When I run I get this error

Enter the (preferably empty!) folder path (without trailing backslash!) that will contain your resulting Notes structure. ex. 'c:\temp\notes': d:\onenote_2_markdown
Ausnahme beim Aufrufen von "GetHierarchy" mit 3 Argument(en):  "Das COM-Objekt des Typs
"Microsoft.Office.Interop.OneNote.Application2Class" kann nicht in den Schnittstellentyp
"Microsoft.Office.Interop.OneNote.IApplicationCOM" umgewandelt werden. Dieser Vorgang konnte nicht durchgeführt
werden, da der QueryInterface-Aufruf an die COM-Komponente für die Schnittstelle mit der IID
"{452AC71A-B655-4967-A208-A4CC39DD7949}" aufgrund des folgenden Fehlers nicht durchgeführt werden konnte: Bibliothek
nicht registriert. (Ausnahme von HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED))."
In D:\Repos\GitHub\ConvertOneNote2MarkDown\ConvertOneNote2MarkDown.ps1:21 Zeichen:3
+   $OneNote.GetHierarchy("", [Microsoft.Office.InterOp.OneNote.Hierarc ...
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : InvalidCastException

Windows 10, OneNote is part of the current Office 365
Or should I try the Windows 10 Version?
Or should I search for the 2016 Version?

The RPC server is unavailable

The script seems to be reading the notebooks OK. It creates the correct directory structure in the target markdown directory.

However, it seems to fail in various ways relating to a missing RPC server.

Exception calling "GetPageContent" with "3" argument(s): "The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)"

and (much later):

Error while publishing file 'Ikigai: The Japanese Secret to a Long and Happy Life Might Just Help You Live a More Fulfilling…' to docx: Exception calling "Publish" with "4" argument(s): "The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)"

There are other errors, but this might be the root cause that cascades down to them.

Section Groups

The script is running fine until it hits a section group, then it exits with "0."

In my OneNote Notebook "root" I have a few sections like "Inbox", "To Read"... then all section groups (like "/bus," "/dev..." these contain many sections and more "sub"-section groups .) My collapsed "root" looks like this:

Inbox
To Read
/ bus
/ dev
/ home
/ life
/ music
/ work

I see in the docs:

Section Groups are listed but do not contain actual data, so these are ignored

Does this mean it can't navigate into a section group and is skipping all the section groups and exiting with no errors? So all sections to be exported need to be moved out of section groups and to the top level/root?

Error when title is longer than 183 characters

First of all, thank you for this miraculous script. I am so close to realizing my dream of moving out of OneNote to Markdown.

I'm almost there. My prior errors were caused by not running OneNote in administrator mode, and not having MS Word installed. Now it's working, except...

Many of my OneNote pages have no title, just content. OneNote substitutes note content for blank titles.

I'm getting errors in this script when my titles are blank and the substituted content is over 183 characters.

Error while publishing file 'Nice. Watts a force of nature. Yeah I play professionally and tour frequently with a singer songwriter out of western canada. Portland is a real gas. Used to love playing at Satyricon back in the day' to docx: Exception calling "Publish" with "4" argument(s): "Exception from HRESULT: 0x80042006"
pandoc.exe: C:\Users\John\Desktop\OneNote\File_Cabinet\-_-_TEST\Nice._Watts_a_force_of_nature._Yeah_I_play_professionally_and_tour_frequently_with_a_singer_songwriter_out_of_western_canada._Portland_is_a_real_gas._Used_to_love_playing_at_Satyricon_back_in_the_day.docx: openBinaryFile: does not exist (No such file or directory)
Get-Content : Cannot find path 'C:\Users\John\Desktop\OneNote\File_Cabinet\-_-_TEST\Nice._Watts_a_force_of_nature._Yeah
_I_play_professionally_and_tour_frequently_with_a_singer_songwriter_out_of_western_canada._Portland_is_a_real_gas._Used
_to_love_playing_at_Satyricon_back_in_the_day.md' because it does not exist.
At C:\Users\John\Desktop\ConvertOneNote2MarkDown-master\ConvertOneNote2MarkDown.ps1:192 char:19
+ ...           ((Get-Content -path "$($fullexportpathwithoutextension).md" ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\John\D...k_in_the_day.md:String) [Get-Content], ItemNotFoundEx
   ception
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand

Error while renaming image file path references for file 'Nice. Watts a force of nature. Yeah I play professionally and tour frequently with a singer songwriter out of western canada. Portland is a real gas. Used to love playing at Satyricon back in the day': You cannot call a method on a null-valued expression.

I am wondering if there is a way to modify your script to handle this, to do something like truncating the title? I have thousands of notes and I can't do it manually.

I've looked at some Onetastic macros but I can't find one that works to add a title to all pages.

Thank you for your help and for creating this script 🙏

Error while publishing file '[xxx]' to docx: Exception calling "Publish" with "4" argument(s): "Class not registered

I'm getting errors like this:

[EDIT: I'm using OneNote 2016. I also have OneNote for Windows 10 installed. I followed all your directions, including Chocolately > Pandoc, and I'm running OneNote 2016 and PowerShell in administrator mode.]

Error while publishing file 'my doc.docx: Exception calling "Publish" with "4" argument(s): "Class not registered

Class not registered
"
couldn't unpack docx container: not enough bytes
Get-Content : Cannot find path 'C:\Users\John\Desktop\OneNote\File_Cabinet\-_Inbox\my_doc.md' because it does not exist.
At C:\Users\John\Desktop\ConvertOneNote2MarkDown-master\ConvertOneNote2MarkDown.ps1:192 char:19
+ ...           ((Get-Content -path "$($fullexportpathwithoutextension).md" ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\John\D...my_doc.md:String) [Get-Content], ItemNotFoundEx
   ception
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand

Error while renaming image file path references for file 'my doc': You cannot call a method on a null-valued expression.

Instructions for Installing from Chocolatey

Hi there, thanks for making this. I installed Chocolately using the instructions in the page you linked to. But I don't know how to install this script using it - I can't find it in their listed packages. Could you write some quick instructions for how to do so? Thanks!

`ConvertOneNote2MarkDown.ps1` exits after taking path, doesn't convert anything

I ran the script, entered in an absolute path that exists, and I briefly saw one of my notebook's names on the terminal window before it closed. I checked the folder to find that only one empty folder was created. What exactly happened?

On a related note, I think it would be very useful to include error messages in the script to better help the user understand why it might have failed, rather than simply exiting immediately.

I modified the code to allow for section groups

I don't know how to share/push this - probably don't have access. But I modified this to allow for top-level section groups, but it kills any top-level section functionality, so you'd have to move all section to a section group to use it. Quite useful for me because I really do need that extra level of hierarchy without creating a new notebook.

I made a function "ProcessSections" that gets called from within the SectionGroup For loop, with the idea that it could then be called from within another loop to process any top-level sections, but got to the edge of my capabilities...

Anyway, feel free to incorporate this however you like.
ConvertOneNote2MarkDownSectionGroups.zip

@johnkyle4, you might be interested in this as well?

Error: Server execution failed

Hi, I was trying to run script over my nootebooks but every time I'm getting the following error:

due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005
(CO_E_SERVER_EXEC_FAILURE)).
At C:\ConvertOneNote2MarkDown\ConvertOneNote2MarkDown.ps1:18 char:14
+   $OneNote = New-Object -ComObject OneNote.Application
+              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [New-Object], COMException
    + FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand

You cannot call a method on a null-valued expression.
At C:\ConvertOneNote2MarkDown\ConvertOneNote2MarkDown.ps1:21 char:3
+   $OneNote.GetHierarchy("", [Microsoft.Office.InterOp.OneNote.Hierarc ...
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Exception calling "ReleaseComObject" with "1" argument(s): "Object reference not set to an instance of an object."
At C:\ConvertOneNote2MarkDown\ConvertOneNote2MarkDown.ps1:216 char:3
+   [System.Runtime.Interopservices.Marshal]::ReleaseComObject($OneNote ...
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : NullReferenceException

Remove-Variable : Cannot find a variable with the name 'OneNote'.
At C:\ConvertOneNote2MarkDown\ConvertOneNote2MarkDown.ps1:217 char:3
+   Remove-Variable OneNote
+   ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (OneNote:String) [Remove-Variable], ItemNotFoundException
    + FullyQualifiedErrorId : VariableNotFound,Microsoft.PowerShell.Commands.RemoveVariableCommand```

I installed pandoc and I am using an absolute path. Onenote is opened when executing the script. OS: Win 10 18363

Replace absolute path of images by relative path

So, I've successfully converted all my Onenote notebooks to markdown, thanks for that! You saved me a tremendous amount of work.

I've moved all notes from the directory I initially put the markdown files to another directory, and noticed that images stopped working because the path referenced is absolute, e.g. 'D:/User/MyNotes/media/...'. I replaced this with the relative path of './media/...' to have them all work again.

I think this can be fixed somewhere around line 181 of the .ps1 file. I attempted a pull request, but I don't know enough of Powershell to replace the part of variable 'fullexportpathwithoutextension' so it just contains './media/.

This would have the script convert Onenote to markdown and lets you then move the notes around as you please!

[minor bug] duplicate names

when there is duplicate names, one will override the other.

image

I dont think it needs to be fixed (just an edgecase). Just want to report it.

What's going wrong here? (apart from the Markdown markup)

PS C:\Users\Toontje\ConvertOneNote2MarkDown> .\ConvertOneNote2MarkDown.ps1
Enter the (preferably empty!) folder path (without trailing backslash!) that will contain your resulting Notes structure. ex. 'c:\temp\notes': ~/export

Ton @ Sites - Company Inc


    Directory: C:\Users\Toontje\export


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----         7/7/2020   5:09 PM                Ton_@_Sites_-_Company_Inc
==============
## Customers
## Tech
--------------
### Quick Notes


    Directory: C:\Users\Toontje\export\Ton_@_Sites_-_Company_Inc


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----         7/7/2020   5:09 PM                Quick_Notes
#### Lab
Error while publishing file 'Lab' to docx: Exception calling "Publish" with "4" argument(s): "Exception from HRESULT: 0x80042006"
pandoc.exe: ~/export\Ton_@_Sites_-_Company_Inc\Quick_Notes\Lab.docx: openBinaryFile: does not exist (No such file or directory)
Get-Content : Cannot find path 'C:\Users\Toontje\export\Ton_@_Sites_-_Company_Inc\Quick_Notes\Lab.md' because it
does not exist.
At C:\Users\Toontje\ConvertOneNote2MarkDown\ConvertOneNote2MarkDown.ps1:192 char:19
+ ...           ((Get-Content -path "$($fullexportpathwithoutextension).md" ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\Ton Ma...ck_Notes\Lab.md:String) [Get-Content], ItemNotFoundEx
   ception
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand

Error while renaming image file path references for file 'Lab': You cannot call a method on a null-valued expression.
#### Company Wifi
Error while publishing file 'Company Wifi' to docx: Exception calling "Publish" with "4" argument(s): "Exception from HRESULT: 0x80042006"
pandoc.exe: ~/export\Ton_@_Sites_-_Company_Inc\Quick_Notes\Company_Wifi.docx: openBinaryFile: does not exist (No such file or directory)
Get-Content : Cannot find path 'C:\Users\Toontje\export\Ton_@_Sites_-_Company_Inc\Quick_Notes\Company_Wifi.md'
because it does not exist.
At C:\Users\Toontje\ConvertOneNote2MarkDown\ConvertOneNote2MarkDown.ps1:192 char:19
+ ...           ((Get-Content -path "$($fullexportpathwithoutextension).md" ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\Ton Ma...\Company_Wifi.md:String) [Get-Content], ItemNotFoundEx
   ception
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand

Error while renaming image file path references for file 'Company Wifi': You cannot call a method on a null-valued expression.
#### JOIN WEBEX MEETING
Error while publishing file 'JOIN WEBEX MEETING' to docx: Exception calling "Publish" with "4" argument(s): "Exception from HRESULT: 0x80042006"
pandoc.exe: ~/export\Ton_@_Sites_-_Company_Inc\Quick_Notes\JOIN_WEBEX_MEETING.docx: openBinaryFile: does not exist (No such file or directory)
Get-Content : Cannot find path 'C:\Users\Ton
Machielsen\export\Ton_@_Sites_-_Company_Inc\Quick_Notes\JOIN_WEBEX_MEETING.md' because it does not exist.
At C:\Users\Toontje\ConvertOneNote2MarkDown\ConvertOneNote2MarkDown.ps1:192 char:19
+ ...           ((Get-Content -path "$($fullexportpathwithoutextension).md" ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\Ton Ma...EBEX_MEETING.md:String) [Get-Content], ItemNotFoundEx
   ception
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand

Error while renaming image file path references for file 'JOIN WEBEX MEETING': You cannot call a method on a null-valued expression.
--------------
### Personal
d-----         7/7/2020   5:09 PM                Personal
#### Home network
Error while publishing file 'Home network' to docx: Exception calling "Publish" with "4" argument(s): "Exception from HRESULT: 0x80042006"
pandoc.exe: ~/export\Ton_@_Sites_-_Company_Inc\Personal\Home_network.docx: openBinaryFile: does not exist (No such file or directory)
Get-Content : Cannot find path 'C:\Users\Toontje\export\Ton_@_Sites_-_Company_Inc\Personal\Home_network.md'
because it does not exist.
At C:\Users\Toontje\ConvertOneNote2MarkDown\ConvertOneNote2MarkDown.ps1:192 char:19
+ ...           ((Get-Content -path "$($fullexportpathwithoutextension).md" ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\Ton Ma...Home_network.md:String) [Get-Content], ItemNotFoundEx
   ception
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand

Error while renaming image file path references for file 'Home network': You cannot call a method on a null-valued expression.

Error when running the script

I've followed the instructions but when running the script I[ve got an error (below).
Windows 10 Version = 20H2 Build 19042.1288
OneNote version = 1808 (Msft office Professional Plus 2019)
Pandoc Version = 2.16.2

Error:

-New-Object : Retrieving the COM class factory for component with CLSID {DC67E480-C3CB-49F8-8232-60B0C2056C8E} failed
due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005
(CO_E_SERVER_EXEC_FAILURE)).
At C:\Users\edugoliv\Downloads\ConvertOneNote2MarkDown.ps1:18 char:14

  • $OneNote = New-Object -ComObject OneNote.Application
  •          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : ResourceUnavailable: (:) [New-Object], COMException
    • FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand

You cannot call a method on a null-valued expression.
At C:\Users\edugoliv\Downloads\ConvertOneNote2MarkDown.ps1:21 char:3

  • $OneNote.GetHierarchy("", [Microsoft.Office.InterOp.OneNote.Hierarc ...
  • + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
    
    

Exception calling "ReleaseComObject" with "1" argument(s): "Object reference not set to an instance of an object."
At C:\Users\edugoliv\Downloads\ConvertOneNote2MarkDown.ps1:219 char:3

  • [System.Runtime.Interopservices.Marshal]::ReleaseComObject($OneNote ...
  • + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : NullReferenceException
    
    

Remove-Variable : Cannot find a variable with the name 'OneNote'.
At C:\Users\edugoliv\Downloads\ConvertOneNote2MarkDown.ps1:220 char:3

  • Remove-Variable OneNote
  • + CategoryInfo          : ObjectNotFound: (OneNote:String) [Remove-Variable], ItemNotFoundException
    + FullyQualifiedErrorId : VariableNotFound,Microsoft.PowerShell.Commands.RemoveVariableCommand
    

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.