Automate OneNote Integration Tasks from PowerShell

Jerod Johnson
Jerod Johnson
Director, Technology Evangelism
Are you in search of a quick and easy way to access OneNote data from PowerShell? This article demonstrates how to utilize the OneNote Cmdlets for tasks like connecting to OneNote data, automating operations, downloading data, and more.

The CData ADO.NET Provider for OneNote is a standard ADO.NET Provider that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to OneNote.

ADO.NET Provider

The ADO.NET Provider provides a SQL interface for OneNote; this tutorial shows how to use the Provider to create, retrieve, update, and delete OneNote data.

Once you have acquired the necessary connection properties, accessing OneNote data in PowerShell can be enabled in three steps.

OneNote uses the OAuth authentication standard. To authenticate using OAuth, create an app to obtain the OAuthClientId, OAuthClientSecret, and CallbackURL connection properties. See the Help documentation for more information.

  1. Load the provider's assembly:

    
    [Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for OneNote\lib\System.Data.CData.OneNote.dll")
        
  2. Connect to OneNote:

     
    $conn= New-Object System.Data.CData.OneNote.OneNoteConnection("OAuthClientId=MyApplicationId; OAuthClientSecret=MySecretKey; CallbackURL=http://localhost:33333;InitiateOAuth=GETANDREFRESH;")
    $conn.Open()
    
  3. Instantiate the OneNoteDataAdapter, execute an SQL query, and output the results:

    
    $sql="SELECT Id, notebook_displayName from Notebooks"
    
    $da= New-Object System.Data.CData.OneNote.OneNoteDataAdapter($sql, $conn)
    $dt= New-Object System.Data.DataTable
    $da.Fill($dt)
    
    $dt.Rows | foreach {
    	Write-Host $_.id $_.notebook_displayname
    }
      

Update OneNote Data


$cmd =  New-Object System.Data.CData.OneNote.OneNoteCommand("UPDATE Notebooks SET Id='Jq74mCczmFXk1tC10GB' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.OneNote.OneNoteParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()

Insert OneNote Data


$cmd =  New-Object System.Data.CData.OneNote.OneNoteCommand("INSERT INTO Notebooks (Id) VALUES (@myId)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.OneNote.OneNoteParameter("@myId","Jq74mCczmFXk1tC10GB")))
$cmd.ExecuteNonQuery()

Delete OneNote Data


$cmd =  New-Object System.Data.CData.OneNote.OneNoteCommand("DELETE FROM Notebooks WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.OneNote.OneNoteParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()

Ready to get started?

Download a free trial of the OneNote Data Provider to get started:

 Download Now

Learn more:

Microsoft OneNote Icon OneNote ADO.NET Provider

Rapidly create and deploy powerful .NET applications that integrate with OneNote data including Notebooks, Sections, Pages, and more!