OneNote Command Line Interface: All You Need to Know

Thumbnail image of Jason Bauer
Jason Bauer
November 20, 2019 (Last Updated: ) | Reading Time: 3 minutes

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:

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:

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

Will result in the following notes being created in OneNote:

You can see that each directory created a section, and each text file was imported as a note.
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:

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.

Download the zip file here: OneNoteCLI (154 kb) Body SHA-256: 527f84714a2cf050dfc27b878031b8bfc2e4b71b031be3920ec3d21c36f6e7bf

AntiVirus Scan: Virus Total Scan Report

If you don't already have a personal binaries directory on your computer, then this is a great opportunity to create one.

Create Your First Note

Continue reading to see how to create a OneNote page from the CLI.

Comments

avatar

HT Tan - 2019-12-24 05:25:07

reply

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.

avatar

Jason Bauer - 2019-12-27 18:50:39

Thanks for the heads up, this has been fixed.

avatar

sharky - 2020-02-06 11:01:07

reply

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?

avatar

Jason Bauer - 2020-03-14 22:19:48

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".

avatar

sharky - 2020-02-06 11:03:05

reply

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

avatar

Marc - 2020-03-13 12:10:54

reply

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.

avatar

Jason Bauer - 2020-03-14 22:20:21

Yes, I do have plans to extend the tool. Your idea is a good one.

avatar

Neil - 2020-03-30 14:58:55

reply

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.

avatar

Jason Bauer - 2020-04-22 16:04:57

Do you have the full version of OneNote 2016 installed? That is (most likely) required.

avatar

Amber - 2020-04-01 17:06:52

reply

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

avatar

Jason Bauer - 2020-04-22 16:00:34

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.

avatar

Jason Bauer - 2020-04-22 16:01:02

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

avatar

Craig - 2020-04-06 11:22:13

reply

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

avatar

Colin T - 2020-04-21 17:15:19

reply

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?

avatar

Jason Bauer - 2020-04-22 16:04:16

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.

avatar

Colin Trost - 2020-04-24 20:09:56

reply

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!

avatar

Jason Bauer - 2020-04-24 20:24:58

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.

avatar

Ravi - 2020-05-10 23:54:09

reply

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](ParserResult1 result, Func2 parsedFunc1, Func2 parsedFunc2, Func2 parsedFunc3, Func2 parsedFunc4, Func2 parsedFunc5, Func2 parsedFunc6, Func2 notParsedFunc) at T4b94rCAjUGwKufifC.vLbHbVURKAN7XyFLrt.bT5cLqIFBw(String[] ) at Yepn4wFD9WDkQU2eM2.NULi5J5V3HNtaiK7wa.xNIcXUGSJ(String[] )

avatar

Jason Bauer - 2020-05-11 03:47:25

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

avatar

Laurent P - 2020-08-12 16:43:16

reply

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

avatar

Jason Bauer - 2020-08-19 22:59:37

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.

avatar

Laurent P - 2020-10-21 12:42:10

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

avatar

Lars - 2020-08-19 01:36:48

reply

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

avatar

Jason Bauer - 2020-09-01 20:43:03

Yes, thanks. I've updated the article.

avatar

Luc Joseph - 2020-09-02 09:25:08

reply

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](ParserResult1 result, Func2 parsedFunc1, Func2 parsedFunc2, Func2 parsedFunc3, Func2 parsedFunc4, Func2 parsedFunc5, Func2 parsedFunc6, Func2 notParsedFunc) at T4b94rCAjUGwKufifC.vLbHbVURKAN7XyFLrt.bT5cLqIFBw(String[] ) at Yepn4wFD9WDkQU2eM2.NULi5J5V3HNtaiK7wa.xNIcXUGSJ(String[] )

C:\onenote-cli>

avatar

Jason Bauer - 2020-09-13 16:03:51

What version of OneNote do you have installed?

avatar

Ali Sabre - 2020-10-16 09:18:45

reply

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.

avatar

Jason Bauer - 2020-10-16 17:16:37

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!

avatar

Eddy Princen - 2020-12-16 13:52:31

reply

Hello, great app. Question, would it be possible to insert templates via de CLI? We have a several pages and subpages set up as a template per project we run. It would be nice if we could insert these from specific template pages withe CLI.

Thanks.

avatar

Jason Bauer - 2020-12-16 16:28:39

Possibly, but I don't quite understand.

What's the difference between inserting content and inserting a template?

Is there a way in OneNote to convert content to a template?

avatar

Karl - 2021-04-06 12:10:44

reply

Hi,

Is it a way to duplicate a page which already exist in onenote ? I created a page as template, i just have to copy it and rename it when i have a new project .

Is this possible with Onenotecli ?

avatar

ivan perez - 2021-07-21 17:47:55

Hello Jason, I am also looking to do the same as Karl. I have a template in onenote and would like to create a new page with that template and just rename it.

avatar

Jason Bauer - 2021-07-22 18:56:21

Great idea, and I think it should be possible. I'll look into it and reply here if I figure it out.

avatar

ivan perez - 2021-07-21 17:55:49

reply

Is there anyway this can be open-sourced so we can help with development of this tool. Having CLI control of OneNote is incredibly useful. I don't know how we have lived this long with out it.

At any rate, thank you for the tool as it is.

avatar

Jason Bauer - 2021-07-22 18:55:37

Yes, eventually. Right now, it's not ready for open source release.

avatar

Mitch - 2023-11-06 02:04:04

reply

Hi,

how to make newline in body ?

avatar

Jason Bauer - 2023-11-06 13:54:55

I think that the easiest way to do this is to use the 'importfolder' feature. Make a directory, the name doesn't matter, and put a text file in that directory that has the multiple lines of text that you want to import. The name of the file will become the title of the note.

Then import that directory into the notebook and section where you want it. Something like this should work:

OneNoteCLI.exe importfolder -n 'Notebook Name' -s 'Section Name' -p 'C:\directory\with\text\file\to\import'

If you have a file in there called 'New Note' that has multiple lines of text, then you'll get a note called 'New Note' with the text contained in the file as the body of the note.

avatar

Victor - 2024-01-19 03:59:34

reply

Do you have any overview of the limitations of html in the pages you create? I've noticed that you can stylize font to an extent, as well as input images through html, but lists and tables don't seem to work for me.

avatar

Jason Bauer - 2024-01-19 09:26:21

I've never tried putting html in the text files, so I don't know about that. I'm surprised it works!

Leave a reply

Thank you! Your comment has been successfully submitted. It will be approved as soon as possible.

More from Efundies