共用方式為


適用於 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:

若要透過 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

範例腳本自定義

執行範例腳本之前,如果尚未安裝應用程式,請在 Windows 上的使用者裝置上安裝 OneNote。 如需詳細資訊,請參閱 OneNote 的部署指南

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

  1. 檢查是否已安裝適用於 Windows 10 的 OneNote,以及應用程式的 AppData 資料夾路徑是否存在 (這會指出使用者是否已在) 之前開啟應用程式,以確認是否需要移轉。
  2. 確認裝置上是否有可執行檔,以檢查是否已安裝適用於 Windows 的 OneNote。
  3. 檢查 OneNote 的版本以取得 Windows 10,以確保其位於具有重要功能的最新版本上,以避免在移轉期間遺失數據。

注意事項

針對 16001.14326.22094 以下的 Windows 10 版本,此腳本不適用於具有 OneNote 的裝置。 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\
    因為卸載適用於 Windows 10的 OneNote 應用程式之後,沙箱路徑就會被刪除。
  2. 卸載 oneNote for Windows 10。
  3. 確定已依每位使用者卸載適用於 Windows 10 的 OneNote,而不是以每個裝置為基礎。
    此程式有助於減輕共用裝置已移除所有帳戶未同步附註的案例。

重要事項

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

#############################################
######   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 支援服務。