Powershell and OneNote – Are You Geek Enough?

powershell onenote skills


I'll admit, when I saw OneNote and Powershell in the same headline, I was like WTF mate.  I started computing with command-line back with MSDOS, but somewhere between Windows XP and World of Warcraft, I just stopped caring about these outmoded nunchuck skillz.  Thankfully, Microsoft decided to go back to its roots and turn the Windows world upside down with Powershell...blah blah balh...


Along comes Brian Dewey and turns my world upside down with the OneNote Powershell Provider.  Command line just officially became cool again!  He does some interesting things with Powershell scripting that is actually useful to the average person.  Below is an excerpt:

"Here’s an example: One thing I wanted was a tool that sends email when pages in a shared OneNote notebook change. This turned out to be pretty easy to do in PowerShell. With the OneNote PowerShell provider, the following lines of script get all of the pages that have changed after a particular time — I use this line in the script to find all pages that have changed since the last time I ran the script.

$changedPages = dir $Notebook -recurse | where-object { ([datetime]$_.lastModifiedTime -gt $targetDate) -and (!$_.PSIsContainer) } 

The dir -recurse command gets me a listing of all of the pages, sections, and section groups in the notebook.

The where-object clause is then used to whittle the list down to only pages (that’s the !$_.PSIsContainer bit) and only pages that have changed after $targetDate.

Then, I can use the following pipeline to export the changed OneNote pages to MHT format and remember the resulting filenames.

$exportedFileNames = $changedPages | export-onenote -output $outputDirectory -format mht | get-propertyvalue ExportedFile 

Finally, I use the Send-SMTPMail cmdlet from the PowerShell Community Extensions to send the email containing all of the changed pages."

After reading this I actually went and downloaded the Powershell as well as this provider thingy.  I feel like I'm 12 again.*yeah I don't have many friends*


Comments (3)
  1. Anonymous says:

    Long ago, when I had my first job in the IT industry, all the engineers I met carried hard-covered exercise

  2. Brian Dewey says:

    Thanks for the kind words. When I get around to it, I hope to add this to the Powershell Community Extensions project. That should make it easier for people to use.

  3. sba923 says:

    It worked like a charm with OneNote 2013, now with OneNote 2016 the latter crashes.

    Any clue?

    Even if OneNote 2016 has introduced API changes, I wouldn’t expect it to crash.

    I can’t recompile the provider ‘cos of missing references.

    Any clue?

Comments are closed.

Skip to main content