This repository has been archived by the owner on Jul 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathClassNotebookTransferAPISample.ps1
63 lines (44 loc) · 2.31 KB
/
ClassNotebookTransferAPISample.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Your Azure AD tenant name. E.g. "contoso.com"
$adTenant = <AZURE_AD_TENANT_NAME>
# Your app's client ID. E.g. "471afe29-4aee-4bc5-9aaf-468ee5bbe20a"
$clientId = <CLIENT_ID>
# Admin login name. E.g. "[email protected]"
$myLogin = <MY_ADMIN_LOGIN>
# Admin password
$myPassword = <MY_ADMIN_PASSWORD>
# The Id of the notebook in the source teacher OneDrive "1-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXXX"
$notebookId = <NOTEBOOK_ID>
# Teacher with the original notebook Office365 login name. E.g. "[email protected]"
$sourceTeacherLogin = <SOURCE_TEACHER_ID>
# Teacher where the notebook will be copied to Office365 login name. E.g. "[email protected]"
$destinationTeacherLogin = <DESTINATION_TEACHER_ID>
# Load Azure AD libraries
$adal = "${env:ProgramFiles(x86)}\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Services\Microsoft.IdentityModel.Clients.ActiveDirectory.dll"
$adalforms = "${env:ProgramFiles(x86)}\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Services\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll"
[System.Reflection.Assembly]::LoadFrom($adal)
[System.Reflection.Assembly]::LoadFrom($adalforms)
# Set Resource URI to Azure Service Management API
$resourceAppIdURI = "https://onenote.com"
# Set Authority to Azure AD Tenant
$authority = "https://login.windows.net/$adTenant"
# Create Authentication Context tied to Azure AD Tenant
$authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList $authority
$userCredential = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.UserCredential" -ArgumentList $myLogin , $myPassword
# Acquire token
$authResult = $authContext.AcquireToken($resourceAppIdURI, $clientId, $userCredential)
$accessToken = $authResult.AccessToken;
# Create a new class notebook
$transferJson = @"
{
sourceUserId: "$sourceTeacherLogin",
destinationUserId: "$destinationTeacherLogin"
}
"@
$transfer = Invoke-RestMethod https://www.onenote.com/api/v1.0/me/notes/classnotebooks/$notebookId/Microsoft.OneNote.Api.NotebookTransfer `
-Method POST `
-ContentType "application/json; charset=utf-8" `
-Headers @{"Authorization" = "Bearer $accessToken"} `
-Body $transferJson
Write-host $transfer
$transfer | clip
Read-Host