Onenote Command Line Interface

OneNoteCLI is a command line interface to OneNote 2016, 2012, and 2010 that allows you to automate the process of creating, deleting, and appending to OneNote pages from both the command line and from batch files.

OneNoteCLI offers the following features from the command line:

  • Create a note
  • Delete a note
  • Create a section
  • Delete a section
  • Append text to a note
  • Import a directory of text and image files

All actions return an exit code that can be detected from a Windows batch file.

Import a Directory of Text and Image Files

One of the most powerful features of OneNoteCLI is the ability to bulk import text files and images, recursively, into a OneNote workbook. With a simple command line you can import 1000’s of notes and sync them to the cloud.

Here’s an example command line to import a directory tree of text notes into an existing notebook:

OneNoteCLI.exe importfolder -n "Test Notebook" -r -d -p "c:\temp\Notes"

Where -r means recursive, and -d means create a Section per directory.

The above command line, when ran on this directory:

OneNote import directory of text files

This is a directory of text files that is to be imported into OneNote.

Will result in the following notes being created in OneNote:

OneNote with a section created per text file

You can see that each directory created a section, and each text file was imported as a note.

In addition to importing text files, OneNoteCLI imports JPG, GIF, BMP, TIF, and PNG files. Each image is imported as it’s own page with the title of the page matching the image filename.

Date and Time

OneNoteCLI uses the date and time stamp of the imported file as the date/time stamp for the created notes. This way you can maintain the integrity of your notes even when doing a mass import.

OneNote Command Line Interface

The OneNoteCLI command line follows the standard:

OneNoteCLI verb [-option "text"] [-option "text"]

The following verbs are supported:

  • importfolder
  • createnote
  • createsection
  • deletenote
  • deletesection
  • appendnote

OneNoteCLI can print a summary of the command line interface if you run it without any parameters:

C:\temp>OneNoteCLI
OneNoteCLI 1.0.0.0
Copyright c  2019
ERROR(S):
  No verb selected.
  importfolder     Import a folder
  createnote       create a note
  createsection    create a section
  deletenote       delete a note
  deletesection    delete a section
  appendnote       append to an existing note
  help             Display more information on a specific command.
  version          Display version information.
C:\temp></code

If you run OneNoteCLI with just a verb it will print the options for that verb:

C:\temp>OneNoteCLI createnote
OneNoteCLI 1.0.0.0
Copyright c  2019
ERROR(S):
  Required option 'n, notebook' is missing.
  Required option 's, section' is missing.
  Required option 't, title' is missing.
  Required option 'b, body' is missing.
  -n, --notebook    Required. (Default: ) Notebook name
  -s, --section     Required. (Default: ) Section name
  -t, --title       Required. (Default: ) New note title
  -b, --body        Required. (Default: ) New note body
  -w, --wait        (Default: false) Wait for keypress
  --help            Display this help screen.
  --version         Display version information.
C:\temp>

Create Notes With Batch Files

OneNoteCLI returns exit code 0 on success, and non-zero on fail. This allows for easy scripting of creating and deleting notes and sections, and even appending to existing notes.

Universal Command Line Interface To OneNote

OneNoteCLI provides a universal command line interface to OneNote that is scriptable. If there are more features that you need implemented let us know in the comments below and we’ll see if it’s possible to add them.

Installation

No installation is necessary, OneNoteCLI can be simply unzipped into a directory and ran from there.

There are 2 files in the zip package that need to be present to run.

  • OneNoteCLI.exe – This is the main program that runs
  • CommandLine.dll – This is an excellent command line parser for .NET

Download the zip file here: OneNoteCLI (154 kb)

Body SHA-256: 527f84714a2cf050dfc27b878031b8bfc2e4b71b031be3920ec3d21c36f6e7bf

AntiVirus Scan: Virus Total Scan Report

 

35 comments

  • I failed to to download “OneNoteCLI.zip” from your given link:
    https://efundies.com/download/OneNoteCLI.zip

    It shows 404 Page Not Found, – I think it’s broken.

    Can you fix that? Thanks.

  • Hello,

    I am trying to use your tool that could suit my needs.

    I come across concerns that I go back to:
    OneNoteCLI.exe createnote -n “TEST” -s “section” -t “title” -b “Body”
    Create note: title
    ERR: That notebook does not exist: TEST

    In the createnote function, would the -p parameter be useful to define the location of the new note be create?

    • The “createnote” function does not have the ability to create a notebook. You need to make sure that the notebook already exists. Also, OneNote is case sensitive, so if you want to use “TEST” then make sure that your notebook is actually called “TEST”.

  • And thank you for thinking of this tool that can serve a few people

  • Hi,

    thank you for OneNote CLI. Do you have any plans to extend the functionality to listing existing entries and reading the contents of an entry?

    Have a very nice day.

  • I would love for this to work. I created a notebook called “Test” and then ran an import and got “ERR: That notebook does not exist: Test”.

    I am using Office 365 and I have both work and personal OneDrive accounts set up, and both accounts with multiple notebooks from each open in OneNote.

  • Love it so far
    is there more documentation on the commands that can be used?

    things i am looking for so far:
    – how to indicate destinations should be in a heirarchy path within a notebook (when adding or appending)
    – i.e. notebook > sectiongroup > sectiongroup > section > page

    – Also when appending in particularly, i dont want to append with just text, but most often would be from clipboard if possible

    TIA
    ~Amber

    • There is currently not a way to create what OneNote calls “groups”. I have managed to get the grouped folders to create, but I have not been able to create a note under the group yet. I’ll work on it some more.

    • Append or insert from clipboard is a great idea, and I’ll add it to the next version.

  • Your app was fantastic, a huge time saver. Thanks so much.

  • I have all of my notes stored in OneDrive. This tool does not seem to know where my notebooks are. Is it possible to use a path or point to the correct directory for my notebooks?

    • Mine too, but I have the “real” version of OneNote 2016 installed, not the Win10 store version, so it is able to work with the notebooks through that version. I suspect if you install the full version of OneNote it will work with your online notes.

      • I have the 2016 version installed from https://www.onenote.com/download I’ve tried creating notebooks in the default USERPROFILE\Documents\Onenote Notebooks folder, and also directly in the USERPROFILE\OneDriveLocation\Onenote Notebooks folder and no matter where I try to create a notebook, the tool always says ERR: That notebook does not exist:TestFolder

        For reference, I’m using the command importfolder

        What path is the application expecting for the notebook?

        • >> What path is the application expecting for the notebook?

          My tool does not take paths into consideration, it asks OneNote behind the scenes to do things. In my personal case my notes are not stored locally, they are in OneDrive. And if I search my hard drive for my notebooks all I can find are files that end in .url and link to OneNote online.

          Can you copy/paste your command here so I can test it on my machine.

          Remember that OneNote is case sensitive, so be sure that the notebook is really named “TestFolder” and note “Test Folder” or “Test folder” or “Testfolder”.

          Also, try running the “createnote” and “createsection” commands and see what happens.

          • Oh I feel dumb. I realized that I was running the command in an elevated administrator command prompt. So the application was looking in the administrator account for the Notebook…which didn’t exist. Changed to a regular non-elevated command prompt and it worked right away.

          • Glad you figured it out. Thanks for posting the update; I’m sure it will help others.

  • No problem. I don’t suppose there’s any chance that the tools used to create this interface for OneNote could be applied to make a similar tool for Outlook, is there? Would love a simplified way to extract Notes out of Outlook into Text files…or even straight into a OneNote Notebook!

    • That’s possible, I already have some Outlook tools that I’ve written that extract messages and do things with them. It shouldn’t be too hard to tie them together.

      How should it work? I assume that the subject becomes the title of the note, but what about selecting which email messages to import? How about import all messages from an outlook folder into a section?

      Or it’s possible to use files as an intermediary step: export all messages in an Outlook folder to files, then run the OneNoteCLI import on that folder of files into a section.

      • Jason, sorry for the delay, I just about forgot about it! So what I’m working on is pulling all Outlook Notes out of a folder (I would presume the Notes folder, but it might be helpful to choose/specify) – but yes, pull all of the notes and use the subject as the name, and dump into OneNote section.

        I’ve tried some things with macros to accomplish this, outputting to text files, and then using the OneNoteCLI to import them, but the macro route is causing issues with notes that have a really long subject causing file path length issues. If the macro I have might help you with your Outlook tool, I can post it

  • Tool works great, but It fails with below error if OneNote is Open

    C:\tools\OneNoteCLI>OneNoteCLI.exe createnote -n Filer -s “Quick Notes” -t “A sample note3” -b “the body of the another text lets see”

    Create note: A sample note3
    Unhandled Exception: System.Runtime.InteropServices.COMException: Retrieving the COM class factory for component with CLSID {D7FAC39E-7FF1-49AA-98CF-A1DDD316337E} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
    at System.Runtime.Remoting.RemotingServices.AllocateUninitializedObject(RuntimeType objectType)
    at System.Runtime.Remoting.Activation.ActivationServices.CreateInstance(RuntimeType serverType)
    at System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(RuntimeType serverType, Object[] props, Boolean bNewObj)
    at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
    at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
    at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
    at System.Activator.CreateInstance(Type type, Boolean nonPublic)
    at System.Activator.CreateInstance(Type type)
    at gByTkmHVAcRhmRB3jk.RfjZhYNZUSD7dgojdx.tMNiH1HyX1EqgQPk411(Type )
    at gByTkmHVAcRhmRB3jk.RfjZhYNZUSD7dgojdx..ctor()
    at T4b94rCAjUGwKufifC.vLbHbVURKAN7XyFLrt.silct7ZjOT(aZ7LGpqqLtA42IeVCA )
    at T4b94rCAjUGwKufifC.vLbHbVURKAN7XyFLrt.G8vc4kHHao(aZ7LGpqqLtA42IeVCA )
    at CommandLine.ParserResultExtensions.MapResult[T1,T2,T3,T4,T5,T6,TResult](ParserResult`1 result, Func`2 parsedFunc1, Func`2 parsedFunc2, Func`2 parsedFunc3, Func`2 parsedFunc4, Func`2 parsedFunc5, Func`2 parsedFunc6, Func`2 notParsedFunc)
    at T4b94rCAjUGwKufifC.vLbHbVURKAN7XyFLrt.bT5cLqIFBw(String[] )
    at Yepn4wFD9WDkQU2eM2.NULi5J5V3HNtaiK7wa.xNIcXUGSJ(String[] )

    • Is it possible that you are running OneNote as a different user than OneNoteCLI? Perhaps UAC has elevated access in OneNote?

  • Dear Jason,

    Thanks for this great tool. I thought that I had found the solution to my problem with your solution but maybe I am not using your application properly. Is there any chance that the importfolder verb could be used to import PDFs as file printout?

    Thank you for your support.

    Regards,

    Laurent

    • I suppose anything is possible. Are they mostly text content? If so then they should be printed to PNG. But if they are mostly image then they should be printed to JPG.

      Perhaps a different approach is to recursively convert the PDF to JPG/PNG/Whatever then import the converted directory.

    • Dear Jason,

      Thank you for your reply. I am not sure why they should be converted to an image. I would like to reach the same behaviour as when I do Insert –> File Printout. I see the content of my PDF displayed and the text is even searchable.

      Or do you mean that the insert file printout first convert the PDF in image format?

      Regards,

      Laurent

      • I don’t know what the feature “Insert->File Printout” does behind the scenes, but I assumed it would run the “print” verb on a file and capture the output as an image. That’s why I suggested converting the PDF to PNG and importing the PNG. Do Onenote make text searching possible in PNG files that contain text?

  • Hi, the provided SHA256 sum only contains 63 characters (252-bit). I believe there should be a “5” at the beginning of the string. Is that right?
    Thanks

  • i ran into to this error when using the command. I’m using W10 64bit.
    Any idea what causing this?

    C:\onenote-cli>OneNoteCLI.exe importfolder -n “ROTA-EMSA” -r -d -p “c:\ROTA-EMSA”

    Import Folder: c:\ROTA-EMSA
    Unhandled Exception: System.Runtime.InteropServices.COMException: Retrieving the COM class factory for component with CLSID {D7FAC39E-7FF1-49AA-98CF-A1DDD316337E} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
    at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
    at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
    at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
    at System.Activator.CreateInstance(Type type, Boolean nonPublic)
    at System.Activator.CreateInstance(Type type)
    at gByTkmHVAcRhmRB3jk.RfjZhYNZUSD7dgojdx.tMNiH1HyX1EqgQPk411(Type )
    at gByTkmHVAcRhmRB3jk.RfjZhYNZUSD7dgojdx..ctor()
    at T4b94rCAjUGwKufifC.vLbHbVURKAN7XyFLrt.UhIckonWly(hlEvAwBprJvDHqAKGp )
    at T4b94rCAjUGwKufifC.vLbHbVURKAN7XyFLrt.F6SchvrmlK(hlEvAwBprJvDHqAKGp )
    at CommandLine.ParserResultExtensions.MapResult[T1,T2,T3,T4,T5,T6,TResult](ParserResult`1 result, Func`2 parsedFunc1, Func`2 parsedFunc2, Func`2 parsedFunc3, Func`2 parsedFunc4, Func`2 parsedFunc5, Func`2 parsedFunc6, Func`2 notParsedFunc)
    at T4b94rCAjUGwKufifC.vLbHbVURKAN7XyFLrt.bT5cLqIFBw(String[] )
    at Yepn4wFD9WDkQU2eM2.NULi5J5V3HNtaiK7wa.xNIcXUGSJ(String[] )

    C:\onenote-cli>

  • Hi, there.. Thank you for “the” great potential to solve years of misery/search:
    My task is to import(insert) an image into Onenote specifically at where the cursor currently is..
    Actually, I do take (hundreds of) screenshots using sharex; do some annotations on them and insert the image into my notes.. I do not want to insert a “printout” of the image; but the file itself..
    In years, this is the first time I see something very close to a possible “full automation” of this workflow..

    I will (hopefully) add your onenotecli.exe to sharex as an automated after-task process. I can pass the path of the image (which is both saved in a folder and also in the clipboard) to your “Onenotecli”.

    Do you think we can do this? I’m sure there’s a lot of folks out there as well who want to insert their clippings into Onenote automatically and we all can benefit..
    Thank you very much for you time and help.

    • I cannot insert an image at the current cursor because there is no “current cursor” since my importer runs without a GUI.

      However I do have an idea for you. With AutoHotKeys you can write a script to do what you want, and you can even call it from a loop in a batch file to import all files in a directory at the current location.

      According to this: https://shortcutworld.com/OneNote/win/Microsoft-OneNote_2016_Shortcuts

      You can use “Alt+N, P” to insert a picture at the current location. This could be called from Autohotkeys in the middle of a script. Hope this helps!

      • My Apologies.. I appreciated your kind and prompt answer.. I would have done the same but its very unfortunate that I am going thru a bottle neck.. A big backlog on posts and some e-mail template thing which I couldnt finish yet which happens to be a pre-requisite for the “waiting” posts..
        But this subject will be a life saver for me because as I said I use it many may times & daily!..
        But the my aim is to make the “single” screenshot (sharex) to be inserted into open onenote page as soon as I take it.. without any extra commands..
        I will be back ASAP about your suggestion..
        Thanks very much again..

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.