共用方式為


適用於 Windows 10 移轉指引的 OneNote

重要事項

適用於 Windows 10的 OneNote 將於 2025 年 10 月終止支援。 建議所有企業客戶從 OneNote for Windows 10 切換到 Windows 上的 OneNote,這可從 Microsoft 市集和 Microsoft 365 訂閱取得。 Windows 上的 OneNote 提供新功能和更新,並可讓您透過 群組原則 來自定義使用者設定。

本文提供將組織從 OneNote for Windows 10 移轉至 OneNote for Windows 的指引。 其中包含識別使用者、自定義移轉腳本,以及確保整個程式中數據完整性的指示。 您可以找到疑難解答步驟和最佳做法,以協助將移轉期間的中斷情況降到最低並保護用戶數據。

在 OneNote 上識別使用者以取得 Windows 10:

若要使用 OneNote for Windows 10 透過 Microsoft Intune 來識別組織中的使用者或裝置,請遵循下列步驟來執行報表:

  • 在 Intune 中,流覽至:所有服務>應用程式 |監視>監視探索>到的應用程式,然後搜尋 「Office.OneNote」。。
  • 尋找開頭16001.xxxxx.xxxxx.x為 的應用程式版本,以識別 Windows 10 使用者的 OneNote。 最新版本為 16001.14326.22008.0

    注意事項

    範例移轉腳本僅適用於版本上 Windows 10 裝置的 OneNote16001.14326.22008.0

範例腳本自定義

為了確保順利移轉至適用於 Windows 的 OneNote,組織必須自定義下列範例腳本,才能完成這些功能:

  • 在用戶裝置上的 Windows 上安裝 OneNote。 如需詳細資訊,請參閱 OneNote 的部署指南

  • 匯報 OneNote for Windows 10 至最新組建,以納入重要功能,並防止移轉未同步附注期間的數據遺失。

    注意事項

    此腳本不會針對不在 16001.14326.22008 版的 Windows 10 裝置更新 OneNote。 IT 系統管理員必須根據組織的原則升級這些裝置。

  • 終止 Windows 10 進程的所有 OneNote。

  • 使用 onenote-uwp://backup: 命令,將任何未同步處理的筆記本備份至使用者的備份資料夾。

    • 備份會儲存在 C:\temp\OneNoteMigration中,不過,您可以隨意編輯路徑以符合組織的需求。
    • 每個備份都會針對每個筆記本建立對應的資料夾,且此路徑內有未同步的區段。
  • 剖析以 UWPBackUpStatus.json 驗證備份是否成功。

    • 使用失敗的備份卸載可能會導致數據遺失。

      注意事項

      若要執行備份,必須安裝適用於 Windows 的 OneNote,且 Windows 10 的 OneNote 必須更新為 16001.14326.22008 版或更新版本。

  • 卸載適用於 Windows 10的 OneNote。

    • 確定已根據使用者卸載適用於 Windows 10 的 OneNote,而不是以裝置為基礎。 此程式有助於減輕共用裝置已移除所有帳戶未同步附註的案例。

重要事項

使用範例腳本之前,您必須先自定義它,以符合組織的特定部署和移轉需求。

#############################################
######   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預設應用程式。
  • 如需 Windows 10,請參閱相關的支援文章,以確保 OneNote 的通訊協定附件正確無誤。

注意

使用在線找到的命令時請小心。 在全組織部署命令之前,請務必先在受控制環境中測試命令,以避免非預期的後果,例如 Remove-AppxPackage 命令所產生的命令。

如需更多協助或查詢,請連絡 Microsoft 支援服務。