如何使用邮箱数据库中的邮箱信息生成 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 How to use the Mbconn utility to generate Active Directory accounts for information store mailboxes

由于 Exchange Server 2007 中不能使用 Mbconn.exe,必须使用 Exchange 命令行管理程序脚本从已断开邮箱收集所需的数据。可以将该数据保存到轻型目录访问协议 (LDAP) 数据交换格式 (LDIF) 文件中,然后,可以将该文件导入 Active Directory。若要将 LDIF 文件导入 Active Directory,必须使用 LDAP 数据交换格式数据 Exchange (LDIFDE) 工具。默认情况下,在运行 Microsoft Windows Server 2003 的计算机上安装 LDIFDE。

本主题说明如何使用 Exchange 命令行管理程序脚本和 LDIFDE 工具,通过邮箱数据库中存储的邮箱信息来生成丢失的 Active Directory 用户帐户。

important要点:
此步骤中的脚本是示例脚本。尽管可以原样使用该脚本,但是,也可以根据组织需要修改该脚本。

开始之前

若要执行此步骤,必须为您使用的帐户委派以下角色:

  • Exchange 收件人管理员角色

  • 帐户操作员角色(对于适用的 Active Directory 容器)

有关权限、角色委派以及管理 Exchange 2007 所需权限的详细信息,请参阅权限注意事项

此外,在执行此步骤之前,请确认以下事项:

  • 已安装具有邮箱服务器角色的 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. 重新启动 Internet 信息服务 (IIS) 管理服务 (IISAdmin)。

    note注意:
    如果安装客户端访问服务器角色的服务器不是您执行恢复操作的服务器,则在该服务器上重新启动 IIS 管理服务。
  5. 重新启动 Microsoft Exchange 信息存储服务 (MSExchangeIS)。

  6. 验证现在用户是否可以登录到其邮箱。

如果在解决此问题时遇到困难,请联系 Microsoft 产品支持部门。有关联系支持部门的信息,请访问 Microsoft Help and Support 网站上的“联系我们”页。

详细信息

有关 Exchange 2007 中的灾难恢复的详细信息,请参阅灾难恢复

有关为应对灾难可以采取的准备措施的详细信息,请参阅尽可能减小灾难影响的最佳实践

有关如何使用 Mbconn.exe 工具在 Exchange 2003 或 Exchange 2000 中实现相同的结果的详细步骤,请参阅 Microsoft 知识库文章 271886 How to use the Mbconn utility to generate Active Directory accounts for information store mailboxes