OneNote for Windows 10 迁移指南

重要

OneNote for Windows 10 将于 2025 年 10 月终止支持。 企业客户应从 OneNote for Windows 10 切换到 OneNote on Windows(可从 Microsoft 应用商店获取,并且订阅为 Microsoft 365)。 Windows 上的 OneNote 提供新功能和更新,并允许你通过组策略自定义用户设置。

本文提供有关将组织从 OneNote for Windows 10 迁移到 OneNote for Windows 的指南。 它包括有关标识用户、自定义迁移脚本和确保整个过程中数据完整性的说明。 你可以找到故障排除步骤和最佳做法,以帮助在迁移过程中最大程度地减少中断和保护用户数据。

在 OneNote 上标识用户以Windows 10:

若要通过 Microsoft Intune 使用 OneNote for Windows 10 标识组织中的用户或设备,请按照以下步骤运行报告:

  • 在Intune中,导航到:所有服务>应用 |监视>监视器>发现的应用,然后搜索“Office.OneNote”。
  • 查找以 16001.xxxxx.xxxxx.x开头的应用程序版本,以标识 Windows 10 用户的 OneNote。 最新版本为 16001.14326.22094.0

    注意

    示例迁移脚本仅适用于版本上的 Windows 10 设备的 OneNote16001.14326.22094.0

示例脚本自定义

运行示例脚本之前,请在用户设备上安装 OneNote(如果尚未安装该应用)。 有关详细信息,请参阅 OneNote 的部署指南

为确保顺利迁移到 OneNote for Windows,组织必须自定义以下示例脚本以按顺序完成这些步骤:

  1. 检查是否已安装 OneNote for Windows 10,以及应用 AppData 文件夹的路径是否存在 (指示用户在) 之前是否已打开应用,以验证是否需要迁移。
  2. 通过验证设备上是否存在可执行文件,检查是否已安装 OneNote for Windows。
  3. 检查 Windows 10的 OneNote 版本,确保其位于最新版本,具有重要的功能,以防止在迁移过程中丢失数据。

注意

此脚本不适用于 OneNote for Windows 10 版本低于 16001.14326.22094 的设备。 IT 管理员必须根据其组织的策略升级这些设备。

若要通过 Appx 下载将用户升级到最新版本,请运行以下命令:
WinGet download 9wzdncrfhvjl --skip-license

  1. 终止Windows 10进程的所有 OneNote。
  2. 使用 onenote-uwp://backup: 命令将任何未同步的节备份到沙盒文件夹。
  3. 将备份存储在以下位置的沙盒中:
    $localAppDataPath\Packages\Microsoft.Office.OneNote_8wekyb3d8bbwe\AppData\Local\OneNote\16.0\BackUp\.
  4. 确保仅备份具有未同步内容的分区,并在其中每个文件夹对应于笔记本的文件夹中进行组织。
  5. 分析 , UWPBackUpStatus.json 验证备份是否成功。

警告

使用失败的备份进行卸载可能会导致数据丢失。

  1. 将备份文件移动到沙盒外部的位置:
    $localAppDataPath\Packages\Microsoft.Office.OneNote_8wekyb3d8bbwe\
    因为卸载 OneNote for Windows 10 应用后,沙盒路径将被删除。
  2. 卸载 OneNote for Windows 10。
  3. 确保 OneNote for Windows 10 是按用户卸载的,而不是在每个设备上卸载的。
    此过程有助于缓解共享设备删除所有帐户的未同步笔记的情况。

重要

在使用示例脚本之前,必须对其进行自定义以满足组织的特定部署和迁移要求。

#############################################
######   OneNote for Windows 10  ############
######   External Migration Script v6  ######
#############################################

## Optional: Helper function to write logs from script to UWPMigrationResult.log File and Console ##
function writeLogsToFileAndConsole {
    Param ([string]$logstring)
    $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
    $logstringWithTimestamp = "[$timestamp] $logstring"
    $backupFolder = [System.Environment]::GetFolderPath('LocalApplicationData') + "\Microsoft\OneNote\16.0\Backup\OneNoteForWindows10"
    $outputFile = $backupFolder + "\UWPMigrationResult.log"

    if (-not (Test-Path $backupFolder))
    {
        New-Item -Path $backupFolder -ItemType Directory
    }

    if (-not (Test-Path $outputFile))
    {
        New-Item -Path $outputFile -ItemType File
    }

    Add-content $outputFile -value "$logstringWithTimestamp"
    Write-Host "$logstringWithTimestamp"
}

## Check if OneNote for Windows 10 is installed and if the AppData path exists ##
function checkOneNoteUWPInstall {
    $folderPath = "$env:LOCALAPPDATA\Packages\Microsoft.Office.OneNote_8wekyb3d8bbwe\LocalState\AppData\Local\OneNote"
    $uwpApp = Get-AppxPackage | Where-Object {$_.Name -eq "Microsoft.Office.OneNote"}
    if ($null -ne $uwpApp)
    {
        $uwpVersion = $uwpApp.Version
        $uwpVersionObject = [System.Version]$uwpVersion
        writeLogsToFileAndConsole "OneNote UWP app version: $uwpVersion"
    }
    else {
        writeLogsToFileAndConsole "OneNote UWP App is not installed"
        exit
    }

    if (Test-Path $folderPath)
    {
        Write-Host "OneNote UWP AppData folder detected"
    }
    else {
        ($null -ne $uwpApp) 
        $uwpApp | Remove-AppxPackage
        writeLogsToFileAndConsole "OneNote AppData folder does not exist and OneNote UWP will now be uninstalled"
        exit
    }
}

## Check if OneNote for Windows is installed by checking the existence of the executable file ##
function checkOneNoteWin32Install {
    $oneNotePath = Join-Path $env:ProgramFiles "Microsoft Office\root\Office16\ONENOTE.EXE"
    
    if (Test-Path $oneNotePath) {
        writeLogsToFileAndConsole "OneNote Win32 is installed"   
    } else {
        writeLogsToFileAndConsole "OneNote Win32 is not installed"
        exit
    }
 }

## Check version of the user's OneNote for Windows 10 app ##
function checkUWPVersion {
    $uwpApp = Get-AppxPackage | Where-Object {$_.Name -eq "Microsoft.Office.OneNote"}
    if ($null -ne $uwpApp)
    {
        $uwpVersion = $uwpApp.Version
        $uwpVersionObject = [System.Version]$uwpVersion

        $updatedVersion = "16001.14326.22094.0"
        $updatedVersionObject = [System.Version]$updatedVersion

        $unsupportedVersion = "16001.14327.10000.0"
        $unsupportedVersionObject = [System.Version]$unsupportedVersion

        if ($uwpVersionObject -ge $unsupportedVersionObject)
        {
            writeLogsToFileAndConsole "Unsupported version of OneNote UWP app. Please check the Microsoft Store for updates"
            exit
        }

        if ($uwpVersionObject -lt $updatedVersionObject)
        {
            writeLogsToFileAndConsole "You must upgrade OneNote UWP to a version higher than 16.0.14326.21802. Please check the Microsoft Store"
            exit
        }
        else
        {
            writeLogsToFileAndConsole "OneNote UWP will backup and uninstall"
        }
    }
    else
    {
        writeLogsToFileAndConsole "No OneNote UWP detected therefore no need for migration"
        exit
    }
}

## Terminate the OneNote for Windows 10 app before executing the rest of the migration script ##
function killProcess {
    if (Get-Process -Name "OneNoteIm" -ErrorAction SilentlyContinue)
    {
        try
        {
            $uwpProcess = Get-Process -Name "OneNoteIm"
            Stop-Process -Id $uwpProcess.Id -Force
            Start-Sleep -Seconds 10
        }
        catch
        {
            writeLogsToFileAndConsole "An error occurred when killing the current OneNote UWP process: $($_.Exception.GetType().FullName)"
            writeLogsToFileAndConsole "$($_.Exception.Message)"
            exit
        }

        writeLogsToFileAndConsole "OneNote UWP process killed"
    }
}

## Run the protocol to back up unsynced sections into the sandbox path ##
function launchBackUp {
    try
    {
        Start-Process "onenote-uwp://backup:"
        Start-Sleep -Seconds 60
        writeLogsToFileAndConsole "OneNote UWP backup initiated"
    }
    catch
    {
        writeLogsToFileAndConsole "An error occurred when starting the backup: $($_.Exception.GetType().FullName)"
        writeLogsToFileAndConsole "$($_.Exception.Message)"
        exit
    }

    writeLogsToFileAndConsole "OneNote UWP backup in progress"
}

## Parse the results in the json files to validate that the backup was successful ##
function parseJson {
    try
    {
        $localAppDataPath = [System.Environment]::GetFolderPath('LocalApplicationData')
        $jsonPath = "$localAppDataPath\Packages\Microsoft.Office.OneNote_8wekyb3d8bbwe\LocalState\AppData\Local\OneNote\16.0\UWPBackUpStatus.json"
        if(!(test-path $jsonPath))
        {
            writeLogsToFileAndConsole "Backup Json file path is not valid"
            exit
        }

        $backupJsonFileContent = Get-Content -Path $jsonPath -Raw | ConvertFrom-Json
        $status = $backupJsonFileContent."UWP Backup Status"
        if ($status -eq "Completed")
        {
            $jsonPath2 = "$localAppDataPath\Packages\Microsoft.Office.OneNote_8wekyb3d8bbwe\LocalState\AppData\Local\OneNote\16.0\UWPSyncStatus.json"
            if(test-path $jsonPath2)
            {
                $syncStatusJsonContent = Get-Content -Raw -Path $jsonPath2
                $syncStatusJsonObject = COnvertFrom-Json $syncStatusJsonContent
                foreach ($key in $syncStatusJsonObject.PSObject.Properties)
                {
                    $value = $syncStatusJsonObject.$($key.Name)
                    if ($value.StartsWith("Contains pending outbounding changes: true,"))
                    {
                        if ($backupJsonFileContent."Number of sections Backed up" -eq 0)
                        {
                            writeLogsToFileAndConsole "No error occurred when backing up but outbounding changes were not backed up successfully"
                            exit
                        }
                        else
                        {
                            break
                        }
                    }
                }
            }

            writeLogsToFileAndConsole "OneNote UWP backup is completed and status is saved"
        }
        elseif ($status -eq "")
        {
            writeLogsToFileAndConsole "$status"
            writeLogsToFileAndConsole "No error occurred but backup did not finish. We cannot continue migration. Consider increasing the Start-Sleep time in line 130 and rerun the script"
            exit
        }
        else
        {
            writeLogsToFileAndConsole "No error occurred but backup status is $status. We cannot continue migration. Consider increasing the Start-Sleep time in line 130 and rerun the script"
            exit
        }
    }
    catch
    {
        writeLogsToFileAndConsole "An error occurred when finishing the backup: $($_.Exception.GetType().FullName)"
        writeLogsToFileAndConsole "$($_.Exception.Message)"
        exit
    }
}

## Copy the backup files to a directory outside of the sandbox path ##
function moveBackup {
try
    {
        $localAppDataPath = [System.Environment]::GetFolderPath('LocalApplicationData')
        $sourcePath = "$localAppDataPath\Packages\Microsoft.Office.OneNote_8wekyb3d8bbwe\LocalState\AppData\Local\OneNote\16.0\BackUp\"
        $destinationPath = [System.Environment]::GetFolderPath('LocalApplicationData') + "\Microsoft\OneNote\16.0\Backup\OneNoteForWindows10\"

        Copy-Item -Path $sourcePath\* -Destination $destinationPath -Recurse -Force

        $sourcePath = "$localAppDataPath\Packages\Microsoft.Office.OneNote_8wekyb3d8bbwe\LocalState\AppData\Local\OneNote\16.0"
        $fileExtensions = "*.json", "*.txt"
        foreach ($fileExtension in $fileExtensions)
        {
            $files = Get-ChildItem -Path $sourcePath -Filter $fileExtension
            foreach ($file in $files)
            {
                Copy-Item -Path $file.FullName -Destination $destinationPath -Force
            }
        }
    }
    catch
    {
        writeLogsToFileAndConsole "An error occurred when moving the backup files: $($_.Exception.GetType().FullName)"
        writeLogsToFileAndConsole "$($_.Exception.Message)"
        exit
    }

    writeLogsToFileAndConsole "Backup files copied successfully from $sourcePath to $destinationPath"
 }

## Uninstall the OneNote for Windows 10 app ##
function uninstallUWP {
    $uwpApp = Get-AppxPackage | Where-Object {$_.Name -eq "Microsoft.Office.OneNote"}
    if ($null -ne $uwpApp)
    {
        $uwpApp | Remove-AppxPackage
        writeLogsToFileAndConsole "OneNote UWP version uninstalled"
    }
}

function MainRoutine {
    checkOneNoteWin32Install
    checkOneNoteUWPInstall
    checkUWPVersion
    killProcess
    launchBackUp
    parseJson
    moveBackup
    uninstallUWP
}

## Executes the main routine ##
MainRoutine

访问迁移的笔记

迁移后,用户可以通过以下方式检索其笔记:

  1. Windows 上打开新的 OneNote 应用程序。
  2. 登录到其帐户。
  3. 打开其笔记本。

如果缺少任何备注,检查前面步骤中创建的备份文件夹。

若要在 Windows 上通过 OneNote 查看备份,请执行以下作:

  • 导航到 “文件 ” -> 打开备份 -> 导航到备份文件路径。

疑难解答

  • UWPBackupStatus.json有关备份和UWPSyncStatus.json同步状态的详细信息,请查看用户的备份文件夹中的 和 文件。

  • 有关迁移过程中遇到的错误,请参阅位于前面 (步骤 1.d) 生成的备份中的日志文件。

onenote-uwp://backup:如果命令失败:

  • 确保 OneNote for Windows 10 应用是链接到onenote-uwp协议的默认应用。
  • 请参阅相关支持文章,确保正确的协议附件到 OneNote Windows 10。

警告

使用联机找到的命令时请谨慎。 在组织范围内部署命令之前,始终在受控环境中测试命令,以避免意外后果,例如 Remove-AppxPackage 命令导致的后果。

如需更多帮助或查询,请联系 Microsoft 支持部门。