OneNote for Windows 10 迁移指南

重要

OneNote for Windows 10 将于 2025 年 10 月终止支持。 建议所有企业客户从 OneNote for Windows 10 切换到 Windows 上的 OneNote,后者可从 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.22008.0

    注意

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

示例脚本自定义

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

  • 在用户设备上在 Windows 上安装 OneNote。 有关详细信息,请参阅 OneNote 的部署指南

  • 汇报 OneNote for Windows 10最新版本,以合并重要功能并防止在迁移未同步笔记期间丢失数据。

    注意

    此脚本不会为不在版本 16001.14326.22008 上的Windows 10设备更新 OneNote。 IT 管理员必须根据其组织的策略升级这些设备。

  • 终止Windows 10进程的所有 OneNote。

  • 使用 onenote-cmd://backup: 命令将任何未同步的笔记本备份到用户的备份文件夹。

    • 备份存储在 中 C:\temp\OneNoteMigration,但是,可以随意编辑路径以满足组织的需求。
    • 每个备份都会为每个笔记本创建一个相应的文件夹,其中包含此路径中的未同步分区。
  • 分析 以 UWPBackUpStatus.json 验证备份是否成功。

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

      注意

      若要执行备份,必须安装 OneNote for Windows,必须将 OneNote for Windows 10 更新到版本 16001.14326.22008 或更高版本。

  • 卸载 OneNote for Windows 10。

    • 确保基于用户而不是设备卸载 OneNote for Windows 10。 此过程有助于缓解共享设备删除所有帐户的未同步笔记的情况。

重要

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

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

## Creates backupFolder and writes log 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"
    $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"
}

## Checks if OneNote UWP is installed and if app data exists, writes version to log file and console ##

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 "UWP OneNote app version: $uwpVersion"
    } else {
        writeLogsToFileAndConsole "OneNote UWP App is not installed"
    exit
    }

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

## Checks if OneNote Win32 is installed by checking the existence of the executable file and checks the version ##

function checkOneNoteWin32Install {
    $oneNotePath = Join-Path $env:ProgramFiles "Microsoft Office\root\Office16\ONENOTE.EXE"
    $registryPath = "HKLM:\SOFTWARE\Microsoft\Office\ClickToRun\Configuration"
    $versionValueName = "ClientVersionToReport"
    $registry = Get-ItemProperty -Path $registryPath
    
    if (Test-Path $oneNotePath) {
        if ($registry.PSObject.Properties[$versionValueName]) {
            $versionValue = $registry.$versionValueName
            writeLogsToFileAndConsole "OneNote Win32 Version Value: $versionValue is installed at path $oneNotePath"   
    } else {
        writeLogsToFileAndConsole "OneNote Win32 is not installed"
        exit
    }
 }   

## Checks for backup folder path
  
    $registryPath = "HKCU:\SOFTWARE\Microsoft\Office\16.0\OneNote\Options\Paths"
    $backupValueName = "BackupFolderPath"
    if (Test-Path $registryPath) {
        $registry = Get-ItemProperty -Path $registryPath
        if ($registry.PSObject.Properties[$backupValueName]) {
            $backupValue = $registry.$backupValueName
            writeLogsToFileAndConsole "OneNote Win32 Backup Path Value: $backupValue"
        }
    }
}

## Updates OneNote for Windows 10 to the latest version available ##

function updateUWPVersion {
    $uwpApp = Get-AppxPackage | Where-Object {$_.Name -eq "Microsoft.Office.OneNote"}
    if ($null -ne $uwpApp) {
        $uwpVersion = $uwpApp.Version
        $uwpVersionObject = [System.Version]$uwpVersion

        $updatedVersion = "16001.14326.22008.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
    }
}
## Terminates 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"
    }
}

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"
}

## Parses 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
    }
}

## Copies the backup files to the local app data folder ##

 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\"

        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"
 }

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
    updateUWPVersion
    launchBackUp
    killProcess
    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 支持部门。