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 Microsoft OneNote data including Notebooks, Notes, Searches, Tags, and more!

Automate OneNote Integration Tasks from PowerShell



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 and the CData ADO.NET Provider for OneNote for tasks like connecting to OneNote data, automating operations, downloading data, and more.

The CData Cmdlets for OneNote are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to OneNote.

PowerShell Cmdlets or ADO.NET Provider?

The Cmdlets are not only a PowerShell interface to OneNote, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete OneNote data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for OneNote. To access OneNote data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for OneNote.

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, you will need to create an app to obtain the OAuthClientId, OAuthClientSecret, and CallbackURL connection properties. See the Help documentation for more information.

PowerShell

  1. Install the module:

    Install-Module OneNoteCmdlets
  2. Connect:

    $onenote = Connect-OneNote -OAuthClientId "$OAuthClientId" -OAuthClientSecret "$OAuthClientSecret" -CallbackURL "$CallbackURL"
  3. Search for and retrieve data:

    $id = "Jq74mCczmFXk1tC10GB" $notebooks = Select-OneNote -Connection $onenote -Table "Notebooks" -Where "Id = `'$Id`'" $notebooks

    You can also use the Invoke-OneNote cmdlet to execute SQL commands:

    $notebooks = Invoke-OneNote -Connection $onenote -Query 'SELECT * FROM Notebooks WHERE Id = @Id' -Params @{'@Id'='Jq74mCczmFXk1tC10GB'}

ADO.NET

  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

PowerShell

Update-OneNote -Connection $OneNote -Columns @('Id','notebook_displayName') -Values @('MyId', 'Mynotebook_displayName') -Table Notebooks -Id "MyId"

ADO.NET

$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

PowerShell

Add-OneNote -Connection $OneNote -Table Notebooks -Columns @("Id", "notebook_displayName") -Values @("MyId", "Mynotebook_displayName")

ADO.NET

$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

PowerShell

Remove-OneNote -Connection $OneNote -Table "Notebooks" -Id "MyId"

ADO.NET

$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()