如何使用信箱資料庫中的信箱資訊產生 Active Directory 帳戶

 

適用版本: Exchange Server 2007 SP3, Exchange Server 2007 SP2, Exchange Server 2007 SP1, Exchange Server 2007

上次修改主題的時間: 2007-04-26

Exchange 信箱是由兩個元件組成:

  • Active Directory 目錄服務使用者帳戶
  • 儲存在 Exchange 信箱資料庫的信箱資料

儲存在信箱資料庫中的資料,包含與信箱相關聯之使用者帳戶的有限資訊。在遺失 Active Directory 資料庫且無法從網域控制站取得任何可用之 Active Directory 備份或系統狀態備份的嚴重損壞情況下,您可以使用信箱資料庫中儲存的資訊來重建使用者帳戶。在 Microsoft Exchange Server 2003 及 Exchange 2000 Server 中,則是使用信箱重新連線工具 (Mbconn.exe) 來完成這項工作。如需 Mbconn.exe 的相關資訊,請參閱 Microsoft 知識庫文章 271886 如何使用 Mbconn 公用程式產生資訊儲存庫信箱的 Active Directory 帳戶

因為 Mbconn.exe 與 Exchange Server 2007 不可以搭配使用,所以必須使用 Exchange 管理命令介面指令碼來蒐集中斷連線信箱的必要資料。然後,可以將資料儲存到輕量型目錄存取通訊協定 (LDAP) 資料交換格式 (LDIF) 檔案,而該檔案之後可以匯入到 Active Directory 中。若要將 LDIF 檔案匯入到 Active Directory,則必須使用 LDAP 資料交換格式資料 Exchange (LDIFDE) 工具。LDIFDE 預設會安裝在執行 Microsoft Windows Server 2003 的電腦上。

本主題說明如何使用 Exchange 管理命令介面指令碼及 LDIFDE 工具,利用儲存在信箱資料庫中的信箱資訊來產生遺失的 Active Directory 使用者帳戶。

important重要事項:
這個程序中的指令碼就是一個範例。雖然您可以依原狀使用撰寫的指令碼,但是也可以修改指令碼,使其符合組織的需求。

開始之前

若要執行這個程序,您使用的帳戶必須已委派下列資格:

  • Exchange 收件者系統管理員角色
  • 適當 Active Directory 容器的帳戶操作員角色

如需管理 Exchange 2007 所需之權限、委派角色以及權利的相關資訊,請參閱權限考量

同時,在執行這些程序之前,請確認下列項目:

  • 已安裝具有 Mailbox server role 的 Exchange 2007 伺服器。
  • Exchange 2007 信箱資料庫已還原並裝載在這部伺服器上。
  • 已建立新的 Active Directory 樹系。
  • 在新的 Active Directory 樹系中,沒有符合已還原之信箱資料庫中信箱的使用者帳戶。

程序

使用信箱資料產生使用者帳戶的程序是由下列步驟組成:

  1. 使用 Exchange 管理命令介面指令碼,蒐集已中斷連線之信箱的必要資料,然後將資料儲存到 LDIF 檔案。這個步驟會在第一個程序中予以說明。
  2. 使用 LDIFDE 工具將 LDIF 檔案匯入到 Active Directory,這樣會在 Active Directory 中產生使用者帳戶。這個步驟會在第二個程序中予以說明。
  3. 使用 Exchange 管理命令介面,將所有信箱連接到透過匯入 LDIF 檔案到 Active Directory 而產生的使用者帳戶。這個步驟會在第三個程序中予以說明。
    note附註:
    本主題中的所有步驟都必須在主控已還原之信箱資料庫的 Exchange 伺服器上執行。

使用 Exchange 管理命令介面指令碼蒐集已中斷連線之信箱的必要資料,並將資料儲存到 LDIF 檔案以匯入到 Active Directory

  1. 使用下列指令碼蒐集已中斷連線之信箱的必要資料,並將資料儲存到 LDIF 檔案。接著,將下列程式碼複製到 CreateLdifFromDisconnectedMailboxes.ps1 文字檔,然後將該檔案儲存到安裝 Exchange 之資料夾下的 Scripts 資料夾。在一般安裝中,這會是 C:\Program Files\Microsoft\Exchange Server\Scripts。

    Param(
    [string] $ContainerDN,
    [string] $Database = "",
    [bool] $append = $false
    )
    
    #function to validate input parameters
    function ValidateParams
    {
    $validInputs = $true
    $errorString = ""
    
    if ($ContainerDN -eq "")
    {
    $validInputs = $false
    $errorString += "`nMissing Parameter:  The -ContainerDN parameter is required. Please pass in a valid container in which to create the user accounts."
    }
    
    if (!$ContainerDN.Contains(","))
    {
    $validInputs = $false
    $errorString += "`nInvalid Container DN.  Make sure to enclose the entire DN in double quotes or it will not be parsed properly."
    }
    
    if (!$validInputs)
    {
    Write-error "$errorString"
    }
    
    return $validInputs
    }
    
    #function to get the display name and alias from mailbox data in the Exchange store
    function ExtractDisplayNameAndAlias($obj)
    {
    [string[]]$legacyDNSplit = $obj.LegacyDN.Split('/')
    $alias = $legacyDNSplit[$legacyDNSplit.Length-1].Remove(0,3).ToLower()
    $output = "dn: CN=" + $obj.DisplayName + "," + $ContainerDN + "`r`nchangetype: add`r`nuserAccountControl: 544`r`nmsExchUserAccountControl: 0`r`npwdLastSet: -1`r`ndisplayName: " + $obj.DisplayName + "`r`nobjectClass: user`r`nsAMAccountName: " + $alias + "`r`n"
    write-output $output | out-file -filePath "c:\ldifout.ldf" -append -noClobber
    }
    
    # Function that returns true if the incoming argument is a help request
    function IsHelpRequest
    {
    param($argument)
    return ($argument -eq "-?" -or $argument -eq "-help");
    }
    
    # Function that displays the help related to this script following
    # the same format provided by get-help or <cmdletcall> -?
    function Usage
    {
    @"
    
    NAME:
    CreateLdifFromDisconnectedMailboxes.ps1
    
    SYNOPSIS:
    Finds all disconnected mailboxes on the local server and creates an LDIF file 
    with an entry for each disconnected mailbox user. Use the LDIFDE utility to import this LDIF file to Active Directory, which generates the user accounts. You can then reconnect Mailboxes 
    to these accounts by using the Connect-Mailbox cmdlet. You can
    specify a particular database, or specify no database to search all databases
    on the local server.
    
    This script is mainly used for disaster recovery scenarios where all data except  
    the mailbox databases have been lost.  In these scenarios, without a backup of Active
    Directory, you must re-create the user accounts so they can be 
    connected to existing mailboxes. This is the main objective of this script.
    
    SYNTAX:
    CreateLdifFromDisconnectedMailbox -ContainerDN <AD Container DN> 
    -Database <Identity of Database> -Append `$false|`$true
    
    AD Container DN is a valid Active Directory container in distinguished name format. This value
    must be enclosed in quotes. Database is the Identity parameter of the 
    database. You can retrieve the Identity value for all databases on the local 
    server by running the following cmdlet:
    
    get-mailboxdatabase -server Server01 | fl Identity
    
    Setting -append to `$true tells the script to append data to the current 
    c:\ldifout.ldf file instead of overwriting it. This is the recommended
    setting if you are piping output from other cmdlets to this script. If the
    -append switch is not included, the script runs automatically in overwrite mode.
    
    EXAMPLES:
    
    "Specifying Database ID"
    CreateLdifFromDisconnectedMailbox -ContainerDN "CN=Users,DC=Domain,DC=com" 
    -Database "SERVER\Storage Group\Database"
    
    "Run Against All Stores on Local Server"
    CreateLdifFromDisconnectedMailbox -ContainerDN "CN=Users,DC=Domain,DC=com" 
    
    "Pipe output of another cmdlet into this script"
    get-mailboxdatabase -server SERVER | foreach {CreateLdifFromDisconnectedMailboxes -ContainerDN 
    
    "CN=Users,DC=domain,DC=com" -Database `$_.Identity -append `$true}
    "@
    }
    
    ################################################################
    ##########################BEGIN SCRIPT##########################
    ################################################################
    
    #Check if this is a help request
    $args | foreach { if (IsHelpRequest $_) { Usage; exit; } }
    
    #Delete existing LDIF file if it is there and append is set to false
    if(!$append){$a = remove-item c:\ldifout.ldf -ea SilentlyContinue}
    
    #Validate all input parameters
    $ifValidParams = ValidateParams;
    if (!$ifValidParams) { exit; }
    
    #find all disconnected mailboxes and get required information
    if ($Database -ne "")
    {
    write "Getting disconnected mailboxes for database $Database"
    $getmbxcmd = get-mailboxstatistics -Database $Database | where {$_.DisconnectDate -ne $null}
    }
    else
    {
    write "Getting disconnected mailboxes for all databases on local server."
       $getmbxcmd = get-mailboxstatistics | where {$_.DisconnectDate -ne $null}
    }
    
    #Make sure at least one disconnected mailbox is found; if not, exit script
    if ($getmbxcmd -eq $null) {write "No disconnected mailboxes found.";exit}
    
    #loop through each disconnected mailbox and write entries to the output file
    foreach ($entry in $getmbxcmd)
    {
    ExtractDisplayNameAndAlias $entry
    }
    
    write "LDIF file successfully written to C:\ldifout.ldf."
    
  2. 啟動 [Exchange 管理命令介面],然後執行下列命令:

    CreateLdifFromDisconnectedMailboxes -ContainerDN "<DN of container to place users>"
    
    important重要事項:
    傳遞給 ContainerDN 參數的 <DN of container to place users> 值,必須是有效 Active Directory 容器的辨別名稱 (DN),而且必須用雙引號括住。例如,若要在 contoso.com 網域中的 Users 組織單位 (OU) 裡放置新使用者帳戶,則應該使用 "CN=Users,DC=contoso,DC=com" 值。

    前面的命令會處理它在其上執行之伺服器上的所有信箱資料庫。如果偏好針對特定信箱資料庫執行指令碼,則可以使用 Database 參數指定想要的資料庫。

    指令碼的輸出會儲存在磁碟機 C 根目錄的 ldifout.ldf 檔案。如果這個檔案已經存在,則指令碼預設會覆寫這個檔案。而將 Append 參數設為 $true,也可以將指令碼附加到現有檔案的後面。

    如需指令碼中所用語法的相關資訊,請執行下列命令:

    CreateLdifFromDisconnectedMailboxes -?
    

使用 LDIFDE 工具將 LDIF 檔案匯入到 Active Directory

  1. 在命令提示中,輸入 ldifde.exe -i -f C:\ldifout.ldf,然後按 ENTER 鍵。

  2. 啟動 [Active Directory 使用者和電腦]。

  3. 如果匯入成功,則使用者應該會出現在執行指令碼時指定的容器中。如果使用者帳戶已存在,則請繼續進行下一個程序。

使用 Exchange 管理命令介面連線信箱

  1. 啟動 Exchange 管理命令介面。

  2. 執行下列命令,連線特定信箱資料庫上的所有信箱。這個命令範例假設您連線的所有信箱都是儲存在伺服器 Server01 之儲存群組 SG1 的信箱資料庫 MBX1 上:

    Get-MailboxStatistics | Where {$_.DisconnectDate -ne $null} | Connect-Mailbox -Database "Server01\SG1\MBX1"
    
  3. 針對位在伺服器上的其他任何信箱資料庫,重複步驟 2。

  4. 重新啟動網際網路資訊服務 (IIS) 管理服務 (IISAdmin)。

    note附註:
    如果安裝 Client Access server role 的伺服器不是執行復原作業的伺服器,則請改為在伺服器上重新啟動 IIS 管理服務。
  5. 重新啟動 Microsoft Exchange 資訊儲存庫服務 (MSExchangeIS)。

  6. 確認使用者現在可以登入他們的信箱。

如果在解決這個問題時發生困難,請連絡 Microsoft 產品支援服務。如需連絡支援人員的相關資訊,請參閱 Microsoft 技術支援服務網站的<連絡資訊>頁面 (英文)。

相關資訊

若要深入了解 Exchange 2007 中的嚴重損壞修復,請參閱嚴重損壞修復

若要深入了解如何準備嚴重損壞,請參閱降低嚴重損壞影響的最佳作法

如需如何使用 Mbconn.exe 工具在 Exchange 2003 或 Exchange 2000 中達成相同結果的詳細步驟,請參閱 Microsoft 知識庫文章 271886 如何使用 Mbconn 公用程式產生資訊儲存庫信箱的 Active Directory 帳戶 (機器翻譯)。

若要確保您目前閱讀的是最新資訊,並尋找其他的 Exchange Server 2007 說明文件,請造訪 Exchange Server 技術資源中心.