James O'Neill's blog

Windows Platform, Virtualization and PowerShell with a little Photography for good measure.

PowerShell and One-Note ... No, really

PowerShell and One-Note ... No, really

  • Comments 2
  • Likes

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 

  $OneNotePath="OneNote:\general\Poweshell\"+(get-date).tostring().replace("/","-").replace(":",".") 

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: , , ,
Comments
Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment