James O'Neill's Blog

October 2, 2007

PowerShell and One-Note … No, really

Filed under: Office,Powershell — jamesone111 @ 8:47 am

Long ago, when I had my first job in the IT industry, all the engineers I met carried hard-covered exercise books wherever they went, and I was encouraged to do the same. These days I still meet old school project managers and engineers who carry a book, but for me OneNote gives me much the same functionality, and since the things I need to remember often stem from meetings or web pages it’s great to be able to click “Send to one-note” in Internet explorer.  There are occasions when I curse the lack of a 64bit Print-to-OneNote driver. [I must check with Darren to see if that’s going to be put right …]

Since I’ve been working with PowerShell I have been regularly cutting and pasting things into Excel (for the text to columns feature) or to OneNote to keep track of what I did. Since PowerShell will pipe output into other windows programs as well well as it’s own cmdlets, I can pipe things into clip.exe to make 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 type

  cd OneNote:\general\Poweshell 

and it takes me to the PowerShell Section (tab) in my General notebook in Onenote. DIR shows me the pages in the section … well great .. it shows what can be done with a provider, but who wants to use the command prompt to explorer their notebooks ?

Here’s a quick bit of PowerShell to make a new page in that section 


new-item -path $OneNotePath -ItemType page

The first line takes the date and converts 1/10/2007 16:55:46 into something valid in a path: 1-10-2007 16.55.46,
new-item,  surprisingly enough creates a page at the given path. By saving the path I can then use it later in an add-content command. like this

  get-history | out-string | add-content $OneNotePath

In fact I might as well put this in a function

  function Out-OneNote
{if ($onenotepath -is [string]) {$input | out-string -width 120 | Add-Content $OneNotePath } }

I’ll leave the else {create a page and output to it} part as an Exercise for the reader. Now I can pipe anything straight into my OneNote page. That’s so cool you could keep a side of beef in it for a month, as someone once said. The next step is to refresh my memory on coding stuff to work with XML data and play with the pages that Get-Content returns. Good spot Viral, and major kudos to Brian for developing it.

Technorati tags: , , ,

This post originally appeared on my technet blog.

Create a free website or blog at WordPress.com.

%d bloggers like this: