CA 備份與還原 Windows PowerShell Cmdlet

適用於:Windows Server 2022、Windows Server 2019、Windows Server 2016、Windows Server 2012 R2、Windows Server 2012

作者:Windows 群組資深支援呈核工程師 Justin Turner

注意

本內容由 Microsoft 客戶支援工程師編寫,適用對象為經驗豐富的系統管理員和系統架構​​師,如果 TechNet 提供的主題已無法滿足您,您要找的是 Windows Server 2012 R2 中功能和解決方案的更深入技術講解,則您是本文的適用對象。 不過,本文未經過相同的編輯階段,因此部分語句也許不如 TechNet 文章那樣洗鍊。

概觀

ADCSAdministration Windows PowerShell 模組是在 Window Server 2012 中引進的。 在 Window Server 2012 R2 中新增了兩個新的 Cmdlet,以支援 CA 的備份和還原。

  • Backup-CARoleService

  • Restore-CARoleService

Backup-CARoleService

ADCSAdministration Cmdlet: Backup-CARoleService

引數 - 需要粗體引數 描述
-Path - 字串 - 儲存備份的位置
- 這是唯一未命名的參數
- 位置參數

範例:

Backup-CARoleService.-Path c:\adcsbackup1

Backup-CARoleService c:\adcsbackup2

-KeyOnly - 備份不含資料庫的 CA 憑證

範例:

Backup-CARoleService c:\adcsbackup3 -KeyOnly

-Password - 指定保護 CA 憑證和私密金鑰的密碼
- 必須是安全字串
- 對 -DatabaseOnly 參數無效

範例:

Backup-CARoleService c:\adcsbackup4 -Password (Read-Host -prompt "Password:" -AsSecureString)

Backup-CARoleService c:\adcsbackup5 -Password (ConvertTo-SecureString "Pa55w0rd!" -AsPlainText -Force)

-DatabaseOnly - 備份不含 CA 憑證的資料庫

Backup-CARoleService c:\adcsbackup6 -DatabaseOnly

-Force 1.可讓您覆寫預先存在於 -Path 參數中所指定位置的備份

Backup-CARoleService c:\adcsbackup1 -Force

-Incremental - 執行增量備份

Backup-CARoleService c:\adcsbackup7 -Incremental

-KeepLog 1.指示命令保留記錄檔。 如果未指定參數,預設會截斷記錄檔,但增量案例除外

Backup-CARoleService c:\adcsbackup7 -KeepLog

-Password <Secure String>

如果使用 -Password 參數,提供的密碼必須是安全字串。 使用 Read-Host Cmdlet 啟動安全密碼輸入的互動式提示,或使用 ConvertTo-SecureString Cmdlet 來指定內嵌密碼。

檢閱下列範例

使用 Read-Host 指定 Password 參數的安全字串

Backup-CARoleService c:\adcsbackup4 -Password (Read-Host -prompt "Password:" -AsSecureString)

使用 ConvertTo-SecureString 指定 Password 參數的安全字串

Backup-CARoleService c:\adcsbackup5 -Password (ConvertTo-SecureString "Pa55w0rd!" -AsPlainText -Force)

Restore-CARoleService

ADCSAdministration Cmdlet: Restore-CARoleService

引數 - 需要粗體引數 描述
-Path - 字串 - 要從中還原備份的位置
- 這是唯一未命名的參數
- 位置參數

範例:

Restore-CARoleService.-Path c:\adcsbackup1 -Force

Restore-CARoleService c:\adcsbackup2 -Force

-KeyOnly - 還原沒有資料庫的 CA 憑證
- 如果已使用 -KeyOnly 選項進行備份,則必須指定

範例:

Restore-CARoleService c:\adcsbackup3 -KeyOnly -Force

-Password - 指定 CA 憑證和私密金鑰的密碼
- 必須是安全字串

範例:

Restore-CARoleService c:\adcsbackup4 -Password (read-host -prompt "Password:" -AsSecureString) -Force

Restore-CARoleService c:\adcsbackup5 -Password (ConvertTo-SecureString "Pa55w0rd!" -AsPlainText -Force) -Force

-DatabaseOnly - 還原不含 CA 憑證的資料庫

Restore-CARoleService c:\adcsbackup6 -DatabaseOnly

-Force - 可讓您覆寫預先存在的索引鍵
- 是選擇性參數,但在就地還原時,可能需要

Restore-CARoleService c:\adcsbackup1 -Force

問題

如果 ConvertTo-SecureString 函式在搭配 -Password 參數使用 Backup-CARoleService 時失敗,則會取得非密碼保護備份。

CA backup and restore

常見錯誤

動作 錯誤 註解
Restore-CARoleService C:\ADCSBackup Restore-CARoleService : 流程無法存取檔案,因為它正由另一個流程使用。 (發生例外狀況於 HRESULT:

0x80070020)

在執行 Restore-CARoleService Cmdlet 之前,請先停止 Active Directory 憑證服務服務
Restore-CARoleService C:\ADCSBackup Restore-CARoleService: 目錄不是空的。 (來自 HRESULT 的例外狀況: 0x80070091) 使用 -Force 參數覆寫預先存在的金鑰
Backup-CARoleService C:\ADCSBackup -Password (Read-Host -Prompt "Password:" -AsSecureString) -DatabaseOnly Backup-CARoleService - 無法使用指定的具名參數來解析參數集。 -Password 參數僅用於密碼保護私密金鑰,因此當您未備份私密金鑰時無效
Restore-CARoleService C:\ADCSBack15 -Password (Read-Host -Prompt "Password:" -AsSecureString) -DatabaseOnly Restore-CARoleService - 無法使用指定的具名參數來解析參數集。 -Password 參數僅用於密碼保護私密金鑰,因此當您未還原私密金鑰時無效
Restore-CARoleService C:\ADCSBack14 -Password (Read-Host -Prompt "Password:" -AsSecureString) Restore-CARoleService: 系統找不到指定的檔案。 (來自 HRESULT 的例外狀況: 0x80070002) 指定的路徑不包含有效的資料庫備份。 可能是路徑無效,或是使用 -KeysOnly 選項進行備份?

其他資源

Active Directory 憑證服務移轉指南

備份 CA 資料庫和私密金鑰

在目的地伺服器上還原 CA 資料庫和設定

試試看:使用 Windows PowerShell 在實驗室中備份 CA

  1. 使用本課程中的命令來備份使用密碼保護的 CA 資料庫和私密金鑰。

  2. 暫時暫停 CA 的還原。