Worlds collide — up until now, I’ve been writing about my personal life. But I also have some things to share about work and technology. I thought about creating a separate website to publish that information, but finally decided that because I’m a combination of geekiness, and proud fatherhood, and other odd interests stuck together, then it’s OK to have this site be a combination of odd things stuck together. So, if you’re here for the baby pictures, then you should just skip the technology posts. And if you’re here for technology, then you should skip the baby pictures.
This is a technology post.
There are two pieces of Microsoft technology that I’ve been using recently and I love. The first is OneNote, which is the first program that I think can replace my cherished paper notebooks. Not only is OneNote a great place to write down all of those thoughts I don’t want to forget, it’s also turning into a wonderful tool for collaboration. Starting in OneNote 2007, OneNote has incredible “shared notebook” functionality. With OneNote 2007, you can have a team of people all contributing information to a single notebook. It’s a great way to build a common repository of knowledge.
The second piece of Microsoft technology I love is PowerShell. This is the ultimate geek-chic tool. It’s a powerful command line / scripting environment.
I now use these programs all the time. And like a Reese’s Peanut Butter Cup, I wondered if these two great technologies would be even better if brought together? So I’ve tried to bring them together in the form of a OneNote PowerShell provider. This is a PowerShell extension that lets you create and manipulate OneNote notebooks, sections, and pages from PowerShell. You can use provider to do some interesting automation using OneNote.
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.
While the core of the script is just those three pipelines, there’s a lot more to the script (217 lines more, to be exact) to do things like parameter validation, formatting, etc. But still, writing and maintaining 220 lines of script was a lot easier than maintaining the couple of thousands of lines of code it would otherwise take to accomplish the same task.
If you want to play with the OneNote PowerShell extension, I’m making it publicly available under the Microsoft Community License. You can find the binary files here: OneNotePowershell.msi. The source files are here: OnPsProvider-1158.zip.
If you install the provider, it will install several sample scripts as well, including the script I’ve been discussing here (Get-OneNoteDigest.ps1).
If you just want to read the documentation that comes with the provider and the scripts, it exists in OneNote format: OneNote PowerShell Documentation.
If you want to use PowerShell with OneNote to build useful tools, let me know. I’ll be curious to see how you use it.





[...] I always feel honoured to work in Office because there are so many incredible people working throughout the org. In particular I met Brian Dewey a few months ago; Brian is a fellow PM in Office and a big OneNote fan and a very savvy geek. What happens when you combine those traits? Well Brian created a OneNote PowerShell Provider : ) Here is what he has to say about it: [...]
[...] This looks very interesting if you are looking for a way to automate some of your OneNote 2007 activities. Once again, Daniel Escapa links to an intriguing bit of programming, this time from Brian Dewey who is a Microsoft Office Product Manager. Brian has created the OneNote PowerShell Provider, which is a PowerShell extension that lets the user create and manipulate OneNote notebooks, sections, and pages. [...]
[...] This looks very interesting if you are looking for a way to automate some of your OneNote 2007 activities. Once again, Daniel Escapa links to an intriguing bit of programming, this time from Brian Dewey who is a Microsoft Office Product Manager. Brian has created the OneNote PowerShell Provider, which is a PowerShell extension that lets the user create and manipulate OneNote notebooks, sections, and pages. [...]
[...] One bonus of moving to a PowerShell world for scripting is that I’m not confined to storing these lines of text in a text file. Thanks to the OneNote PowerShell Provider, my PowerShell scripts can manipulate text on OneNote pages as well as in text files. So if you live out of OneNote and want to bring the simplicity of a todo.txt-style todo list to the place you keep the rest of your notes, well, now you have a set of scripts that can help you manipulate those todo items. [...]
[...] Brian Dewey has created a OneNote PowerShell Provider PowerToy which uses the power of scripting to get to OneNote data. [...]
I have been attempting to modify the “Get OneNote Digest” script to export OneNote pages as pdf files. Although I am able to export OneNote pages as DOC, and MHT files, I have been unsuccessful in generating pdf files. I have however, installed the MS plugin that allows user save files in pdf format.
Is there anything you can tell me about using the OneNote Powershell provider to export files in PDF format?
Thanks,
Justin
My teammate James O’Neill flipped when he read this, this a fantastic extension! Hope the good work continutes. Have you thought opening up a Codeplex.com project page?
[...] Uses for OneNote #1342: OneNote and Powershell. [...]
[...] and a very savvy geek. What happens when you combine those traits? Well Brian created a OneNote PowerShell Provider : ) Here is what he has to say about [...]
[...] be thrilled to learn that a PowerShell Provider for OneNote exists. Here is where you can get it:: http://bdewey.com/2007/07/18/onenote-powershell-provider/ It is free and comes with full sources, so it may in fact also be a great starting point for anyone [...]
[...] be thrilled to learn that a PowerShell Provider for OneNote exists. Here is where you can get it: http://bdewey.com/2007/07/18/onenote-powershell-provider/ It is free and comes with full sources, so it may in fact also be a great starting point for anyone [...]
[...] the paste operation easier… But Viral found something on Brian Dewey’s blog which just blows that away. A OneNote provider for PowerShell. Whoa … a provider ? Yes I can [...]
[...] One sad casualty of my move to Windows 7 and Office 2010 is the OneNote PowerShell provider. http://bdewey.com/2007/07/18/onenote-powershell-provider/ [...]
[...] OneNote PowerShell provider Posted on Wednesday 22 June 2011 by richardsiddaway One sad casualty of my move to Windows 7 and Office 2010 is the OneNote PowerShell provider. http://bdewey.com/2007/07/18/onenote-powershell-provider/ [...]