---
schema_version: "1"
id: cd8d5b1d479ce9daadf61ce890408cb1b5a2cbdd0e63cbe31d706b25c8b4c36c
title: 範例：撰寫移轉計劃的指令碼
collection: tableau
version: current
locale: zh-tw
portal_url: https://docs.salesforce.com/tableau/current/zh-tw/online/cmt-scripting_migration_example.md
canonical_url: https://help.tableau.com/current/online/zh-tw/cmt-scripting_migration_example.htm
source_site: help.tableau.com
content_type: documentation
content_hash: 972ffff45634e3438ebde599667de8661a3d1a9eac11c10764050334e33f8e03
description: Sample script for scripting a multi-plan migration with the Content Migration Tool console runner.
---
[跳至主要內容](#main-content)

# 範例：撰寫移轉計劃的指令碼

**附註：**本主題包含範例指令碼，可供您據以撰寫多重計劃移轉的指令碼，以符合您的需求和環境。此指令碼僅供您作為範例使用，不適合以原狀執行。有關使用主控台執行器的詳細指示，請參閱[使用 Tableau Content Migration Tool 控制台執行器](https://help.tableau.com/current/online/zh-tw/cmt-deployment_console_runner.htm)。

執行移轉的 Tableau Content Migration Tool 命令列公用程式可用來從外部排程器（例如 Windows 工作排程器）或自訂指令碼自動執行移轉計劃。主控台執行器只會執行一個移轉計劃（儲存在 .edt 檔案中）。如果您有一組移轉計劃需要以群組的形式執行，您可以搭配使用自訂指令碼與 Content Migration Tool 主控台執行器。

下列範例以 PowerShell 撰寫，並使用主控台執行器以群組的形式執行一份移轉計劃清單。

下列範例程式碼將示範：

- 使用主控台執行器以群組的形式執行多個移轉計劃。
- （選擇性）在群組中的任一移轉失敗時，立即中止計劃群組的部署。
- 使用主控台執行器的結束代碼，判斷移轉是否失敗或記錄警告。

\# List of migration plans to execute as a group.
$planFiles = @(
	'customer 1.tcmx',
	'customer 2.tcmx'
)

# True of false whether to continue with the next plan if a migration fails.
$continueOnFailure = $false
			
# Path to the CMT console runner executable
$runnerExe = 'C:\\Program Files (x86)\\Tableau\\Tableau Content Migration Tool\\tabcmt-runner.exe'

# Store the exit code from the previously run migration plan.
$lastResult = -1
			
# Loop through and run each migration plan one at a time.
$planFiles | % {
	$file = $\_
			
	if ($lastResult -ge 2 -and -not($continueOnFailure)) {
		Write-Warning "Skipping plan because previous migration failed. \`nSkipped plan: $file"
		return
	}
			
	Write-Verbose "Running migration plan: $file"
	& $runnerExe $file
       $lastResult = $LASTEXITCODE
 
 	if ($lastResult -ge 2) {
		Write-Error "Migration failed. See output or log file for error details.\`nPlan: $file" -ErrorAction 'Continue'
	}
	elseif ($lastResult -eq 1) {
		Write-Warning "Migration completed with warnings. See output or log file for warning details.\`nPlan: $file"
	}
}

## 誰可以執行此動作

若要編寫移轉計劃，您必須具備以下項目：

- Content Migration Tool 機器上的管理員權限。
- 具有 Explorer 角色或更高等級角色的 Tableau 站點使用者帳戶。
- 在來源站點上檢視及下載工作簿/儲存副本權限。
- 目的地站點的發佈權限。