PowerShell module for manipulating Microsoft OneNote data using the Microsoft Graph REST API.
Following on from OneNoteUtilities this module uses the Microsoft Graph API instead of the desktop COM objects.
Following Microsoft's decision to continue support for the desktop version of OneNote I have added an additional command (Invoke-ONDesktop
) to open OneNote pages in the desktop application specifically, rather than whichever application has been registered as the handler for the onenote:
protocol.
This module provides the following functions:
- Get-ONConfig
- Get-ONDefaultSection
- Get-ONElement
- Get-ONNoteBook
- Get-ONNoteBooks
- Get-ONPage
- Get-ONPagePreview
- Get-ONPages
- Get-ONPageXML
- Get-ONRecentNoteBooks
- Get-ONResource
- Get-ONResources
- Get-ONSection
- Get-ONSectionGroup
- Get-ONSectionGroups
- Get-ONSections
- Get-ONSessionVariables
- Get-ONTableAsObject
- Get-ONTokenStatus
- Invoke-ONApp
- Invoke-ONDesktop
- Invoke-ONWeb
- New-ONElement
- New-ONNoteBook
- New-ONPage
- New-ONPageXML
- New-ONSection
- New-ONSectionGroup
- Remove-ONPage
- Save-ONConfig
- Set-ONPageLevel
- Test-ONUtilities
- Update-ONElement
Remove-ONNoteBookRemove-ONSectionGroupRemove-ONSectionRemove-ONElementCopy-ONPage
Before installing the module, ensure that you have a client ID for the Microsoft Graph service. See the following for more information https://docs.microsoft.com/en-us/graph/auth-register-app-v2.
Create a config XML file containing your client ID and security scope information, named OneNoteUtilities.config and place it in your .config folder. There is a template file in this repo on GitHub.
Download the module, extract it to a location in your modules path and use Import-Module
. The process of importing will trigger an attempt to connect to Microsoft Graph. This will fail if you haven't set up the config file.
Suppose that you need to create a new Notebook, create Sections for the months of the year and create a Page for each day of each month. You would like the title of each page to look like 'Friday, 26th June 2019' in format. With OneNoteUtiliesGraph you can do this:
Import-Module OneNoteUtilitiesGraph
#Create NoteBook
$NoteBook = New-ONNoteBook -DisplayName (Get-Date).Year
#Create Section per Month
(1..12) | % {
$month = $_;
$monthName = (Get-Date -Month $_).ToString('MMMM')
$Section = New-ONSection -Id $NoteBook.Id -DisplayName $monthName
#Create Page per Day
(1..$([DateTime]::DaysInMonth((Get-Date).Year,$month))) | % {
$Page = New-ONPageXML -Title $((Get-Date -Year (Get-Date).Year -Month $month -Day $_).toString("dddd dd MMMM yyyy"))
New-ONPage -URI $Section.pagesURL -Page $Page
}
}
It takes a couple of minutes, but that's much shorter than creating 12 month Sections and 365 day Pages by hand.
This could just as easily be applied to lists of staff, students or objects in Active Directory.
Get-ONPages -Filter "parentNoteBook/displayname eq '2019' and startswith(title,'Monday')"
https://github.com/wightsci/OneNoteUtilitiesGraph/wiki
- Support for Tags
- HTML Templates for Pages
- Merge-to-OneNote
- Out-ONPage
- New Graph REST features as they are released