Automate OneNote Integration Tasks from PowerShell
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.
-
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for OneNote\lib\System.Data.CData.OneNote.dll") -
Connect to OneNote:
$conn= New-Object System.Data.CData.OneNote.OneNoteConnection("OAuthClientId=MyApplicationId; OAuthClientSecret=MySecretKey; CallbackURL=http://localhost:33333;InitiateOAuth=GETANDREFRESH;") $conn.Open() -
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()
CodeProject