PowerShell を使用してメールボックスを移動する

PowerShell を使用して、Exchange 管理センター (EAC) に加えてメールボックスを移動できます。

オンプレミスのメールボックスをExchange Online organizationに移動する

PowerShell を使用してオンプレミスのメールボックスを Exchange Online に移動するには、次の手順を実行します。

  1. Exchange Online PowerShell に接続する: 管理者として PowerShell を起動し、次のコマンドを実行して Exchange Online PowerShell に接続します。

    PS C:\> Connect-ExchangeOnline
    
  2. 移行エンドポイントのリモート サーバー URL を検索する: Get-MigrationEndpoint コマンドレットを使用してリモート サーバーの URL を取得します。

    Get-MigrationEndpoint | Format-List Identity, RemoteServer
    

    次の出力が表示されます。

    PS C:\> Get-MigrationEndpoint | Format-List Identity, RemoteServer
    
    Identity     : Hybrid Migration Endpoint - EWS (Default Web Site)
    RemoteServer : <GUID>.resource.mailboxmigration.his.msappproxy.net
    

    注:

    上記のコマンド構文出力の RemoteServer 値は、 ハイブリッド構成ウィザード (HCW) を実行して生成されます。

  3. 次の部分で必要に応じて、 RemoteServer の値をコピーします。

    注:

    上記の出力コマンド構文に表示されるリモートサーバーの値は、ユーザーが [ハイブリッド トポロジ] ページで [Exchange の最新のハイブリッド トポロジを使用する] を選択したときに生成されます。

  4. PowerShell を使用してプライマリ メールボックスとアーカイブ メールボックスを Exchange Online に移動する新しい移動要求を作成する

    • 以下の詳細を入力して新しい移動要求を作成し、プライマリ メールボックスとアーカイブ メールボックスを Exchange Online に移動します。

      • ID: メールボックス名またはメール アドレス。
      • RemoteHostName: 手順 2 でコピーしたリモート サーバー。
      • TargetDeliveryDomain: Exchange Online organization メールボックスに使用されるプライマリ SMTP ドメイン。
      • RemoteCredential: 特権のあるオンプレミスの管理者アカウント。

      コマンドを実行すると、資格情報サインイン要求が表示されます。

      New-MoveRequest -Identity "Maisha.Lee@contoso.com" -Remote -RemoteHostName "mail.contoso.com" -TargetDeliveryDomain "<domain>.mail.onmicrosoft.com" -RemoteCredential (Get-Credential)
      
    • オンプレミスの資格情報 (RemoteCredential) のパスワードを入力します。

  5. PowerShell を使用して複数のメールボックスを Exchange Online に移動する

    • Users.csv という名前の CSV ファイルを作成し、ディレクトリ C:\migration に配置します。

    • CSV ファイルを開き、ヘッダー列に「メールアドレス」という名前を付けて、Exchange Online に移動するすべてのメールボックスを入力します。

      移動するメールボックスの詳細が入力されている CSV を示すスクリーンショット。

    • 次のスクリプトをコピーし、最初の 3 行を変更します。 その後、スクリプトを実行します。

      $Mailboxes = Import-Csv "C:\Migration\Users.csv"
      $RemoteHostName = "mail.contoso.com"
      $TargetDeliveryDomain = "<domain>.mail.onmicrosoft.com"
      $OnPremCred = (Get-Credential)
      
      # Move mailboxes in CSV file to Exchange Online
      foreach ($Mailbox in $Mailboxes) {
      $params = @{
      Identity               = $mailbox.EmailAddress
      Remote                 = $true
      RemoteHostName         = $RemoteHostName
      TargetDeliveryDomain   = $TargetDeliveryDomain
      RemoteCredential       = $OnPremCred
             }
      
      New-MoveRequest @params
      
         }
      
  6. PowerShell を使用してプライマリ メールボックスのみを Exchange Online に移動する

    アーカイブ メールボックスの場所が Exchange Online にあり、プライマリ メールボックスの場所が Exchange オンプレミスにあるシナリオがあります。次のコマンドを実行します。

    $Mailboxes = Import-Csv "C:\Migration\Users.csv"
    $RemoteHostName = "mail.contoso.com"
    $TargetDeliveryDomain = "<domain>.mail.onmicrosoft.com"
    $OnPremCred = (Get-Credential)
    
    # Move mailboxes in CSV file to Exchange Online
    foreach ($Mailbox in $Mailboxes) {
    $params = @{
    Identity               = $mailbox.EmailAddress
    Remote                 = $true
    RemoteHostName         = $RemoteHostName
    TargetDeliveryDomain   = $TargetDeliveryDomain
    RemoteCredential       = $OnPremCred
           }
    
    New-MoveRequest @params
    
       }
    

    その結果、次のエラー メッセージが表示されます。これは、エラー メッセージの後に表示される大きなコマンド構文の一部です。

    You must specify the PrimaryOnly parameter
    Target user ‘XXXXXX’ already has an archive mailbox.
    
    PS C:\> New-MoveRequest -Identity "Maisha.Lee@contoso.com" -Remote -RemoteHostName "mail.contoso.com" -TargetDeliveryDomain "<domain>.mail.onmicrosoft.com" -RemoteCredential (Get-Credential)
    You must specify the PrimaryOnly parameter.
    Target user 'Maisha Lee' already has an archive mailbox.
    + CategoryInfo          : NotSpecified: (:) [New-MoveRequest], MailboxReplicationPermanentException
    + FullyQualifiedErrorId : [Server=PAXP190MB1743,RequestId=3f8179c3-aa93-453f-9e14-d824968f34c4,TimeStamp=5/28/2022
    7:19:13 AM] [FailureCategory=Cmdlet-MailboxReplicationPermanentException] FE8B9422,Microsoft.Exchange.Management.
    Migration.MailboxReplication.MoveRequest.NewModernMoveRequest
    + PSComputerName        : outlook.office365.com
    

    エラー メッセージが表示されたら、次の手順を実行します。

    • プライマリ メールボックスを Exchange Online だけに移動するという新しい移動要求を作成する際のエラーを解決するには、前述のコマンド構文に -PrimaryOnly パラメータを追加します。

    • 次の詳細を入力します。

      • ID: メールボックス名またはメール アドレス。
      • RemoteHostName: 手順 2 でコピーしたリモート サーバー。
      • PrimaryOnly: 値を空のままにします。
      • TargetDeliveryDomain: Exchange Online organization メールボックスに使用されるプライマリ SMTP ドメイン。
      • RemoteCredential: 特権のあるオンプレミスの管理者アカウント。

      新しい移動要求に対してコマンドを実行すると、次のコマンド構文に示すように資格情報サインイン要求が表示されます。

      New-MoveRequest -Identity "Maisha.Lee@contoso.com" -Remote -RemoteHostName "mail.contoso.com" -PrimaryOnly -TargetDeliveryDomain "<domain>.mail.onmicrosoft.com" -RemoteCredential (Get-Credential)
      
    • オンプレミスの資格情報 (RemoteCredential) のパスワードを入力します。

  7. PowerShell を使用してアーカイブ メールボックスのみを Exchange Online に移動する

    PS C:\> New-MoveRequest -Identity "Maisha.Lee@contoso.com" -Remote -RemoteHostName "mail.contoso.com" -TargetDeliveryDomain "<domain>.mail.onmicrosoft.com" -RemoteCredential (Get-Credential)
    You must specify the PrimaryOnly parameter.
    Target user 'Maisha Lee' already has an archive mailbox.
    + CategoryInfo          : NotSpecified: (:) [New-MoveRequest], MailboxReplicationPermanentException
    + FullyQualifiedErrorId : [Server=PAXP190MB1743,RequestId=3f8179c3-aa93-453f-9e14-d824968f34c4,TimeStamp=5/28/2022
    7:19:13 AM] [FailureCategory=Cmdlet-MailboxReplicationPermanentException] FE8B9422,Microsoft.Exchange.Management.
    Migration.MailboxReplication.MoveRequest.NewModernMoveRequest
    + PSComputerName        : outlook.office365.com
    
    • アーカイブ メールボックスを Exchange Online にのみ移動する新しい移動要求を作成するときのエラーを解決するには、上記のコマンド構文に ArchiveOnly パラメータを追加します。
    • 次の詳細を入力します。
      • ID: メールボックス名またはメール アドレス。
      • RemoteHostName: 手順 2 でコピーしたリモート サーバー。
      • ArchiveOnly: 値を空のままにします。
      • TargetDeliveryDomain: Exchange Online organization メールボックスに使用されるプライマリ SMTP ドメイン。
      • RemoteCredential: 特権のあるオンプレミスの管理者アカウント。

    新しい移動要求に対してこのコマンドを実行すると、次のコマンド構文に示すように、資格情報サインイン要求が表示されます。

    New-MoveRequest -Identity "Maisha.Lee@contoso.com" -Remote -RemoteHostName "mail.contoso.com" -ArchiveOnly -TargetDeliveryDomain "<domain>.mail.onmicrosoft.com" -RemoteCredential (Get-Credential)
    

    オンプレミスの資格情報 (RemoteCredential) のパスワードを入力します。

  8. メールボックスの移動状態を取得する

    • Get-MoveRequest コマンドレットを使用して、メールボックスの移動要求の状態を取得します。

      Get-MoveRequest -Identity "Maisha.Lee@contoso.com" | Get-MoveRequestStatistics
      
    • 次のコマンドを実行して、すべてのメールボックス移動要求を取得します。

      Get-MoveRequest | Get-MoveRequestStatistics
      

      次のスクリーンショットに示すように、出力にはメールボックスの移動状態が [完了 済み] 状態として表示されます。

      ユーザーがメールボックスの移動状態を取得できるようにするコマンドを示すスクリーンショット。

      それ以外の場合、メールボックスの移動要求を完了できない場合は、移動要求を一時停止して再開できます。

Exchange Online メールボックスをオンプレミスorganizationに移動する

PowerShell を使用して Exchange Online メールボックスをオンプレミスorganizationに移動するには、次の手順を実行します。

  1. Exchange Online PowerShell に接続する: 管理者として PowerShell を起動し、次のコマンドを実行して Exchange Online PowerShell に接続します。

    PS C:\> Connect-ExchangeOnline
    

    注:

    Exchange Online メールボックスをオンプレミスにプルしていません。 実際に、Exchange Online メールボックスをオンプレミスにプッシュしています。 そのため、Exchange Online に接続し、Exchange Online PowerShell からコマンドを実行する必要があります。

  2. 移行エンドポイントのリモート サーバー URL を検索する: Get-MigrationEndpoint コマンドレットを使用してリモート サーバーの URL を取得します。

    Get-MigrationEndpoint | Format-List Identity, RemoteServer
    

    次の出力が表示されます。

    Identity     : Hybrid Migration Endpoint - EWS (Default Web Site)
    RemoteServer : mail.contoso.com
    

    注:

    上記のコマンド構文出力の RemoteServer 値は、 ハイブリッド構成ウィザード (HCW) を実行して生成されます。

  3. 次の部分で必要に応じて、 RemoteServer URL 値をコピーします。

  4. PowerShell を使用してプライマリ メールボックスとアーカイブ メールボックスを Exchange Online から移動するための新しい移動要求を作成する

    • プライマリ メールボックスとアーカイブ メールボックスを Exchange Online から移動するための新しい移動要求の作成の一部として、次の詳細を入力します。

      • ID: メールボックス名またはメール アドレス。
      • RemoteTargetDatabase: Exchange オンプレミス メールボックス データベース。
      • RemoteHostName: 手順 2 でコピーしたリモート サーバー。
      • TargetDeliveryDomain: Exchange Online organization メールボックスに使用されるプライマリ SMTP ドメイン。
      • RemoteCredential: 特権のあるオンプレミスの管理者アカウント。

      新しい移動要求を作成するために実行するコマンドは次のとおりです。

      New-MoveRequest -OutBound -RemoteTargetDatabase "DB01" -RemoteHostName "mail.contoso.com" -TargetDeliveryDomain "contoso.com" -RemoteCredential (Get-Credential)
      
    • コマンドの実行後に次のコマンド構文で示されているように、資格情報サインイン要求のオンプレミスの資格情報 (RemoteCredential) のパスワードを入力します。

      PS C:\> Get-Mailbox -Identity "Jordy.Twin@contoso.com" | New-MoveRequest -OutBound -RemoteTargetDatabase "DB01" -RemoteHostName "mail.contoso.com" -TargetDeliveryDomain "contoso.com" -RemoteCredential (Get-Credential exoip\administrator)
      
      DisplayName Status TargetDatabase
      ----------- ------ --------------
      Jordy Twin  Queued
      

      オンプレミスの資格情報のパスワードを含む上記のコマンドを実行すると、次のエラーが表示される可能性があります。

      • メールボックス GUID を持つ受信者が見つからない
      • ソース受信者と対象受信者のアーカイブ GUID が一致しません
  5. PowerShell を使用して Exchange Online からプライマリ メールボックスのみを移動する

    • プライマリ メールボックスとアーカイブ メールボックスの場所が Exchange Online 内にあり、プライマリ メールボックスのみを移動する場合は、新しい移動を作成するために実行するコマンドに -PrimaryOnly および -ArchiveDomain パラメーターを追加し、コマンド構文に次の詳細を入力します。

      • ID: メールボックス名またはメール アドレス。
      • OutBound: 値を空のままにします。
      • RemoteTargetDatabase: Exchange オンプレミス メールボックス データベース。
      • RemoteHostName: 手順 2 でコピーしたリモート サーバー。
      • PrimaryOnly: 値を空のままにします。
      • ArchiveDomain: Exchange Online organization メールボックスに使用されるプライマリ SMTP ドメイン。
      • TargetDeliveryDomain: Exchange Online organization メールボックスに使用されるプライマリ SMTP ドメイン。
      • RemoteCredential: 特権のあるオンプレミスの管理者アカウント。

      新しい移動要求を作成するために実行するコマンドは次のとおりです。

      New-MoveRequest -OutBound -RemoteTargetDatabase "DB01" -RemoteHostName "mail.contoso.com" -PrimaryOnly -ArchiveDomain "<domain>.mail.onmicrosoft.com" -TargetDeliveryDomain "contoso.com" -RemoteCredential (Get-Credential)
      

      コマンドを実行すると、次のコマンド構文に示すように資格情報サインイン要求が表示されます。

      PS C:\> Get-Mailbox -Identity "Jordy.Twin@contoso.com" | New-MoveRequest -OutBound -RemoteTargetDatabase "DB01" -RemoteHostName "mail.contoso.com" -PrimaryOnly -ArchiveDomain "<domain>.mail.onmicrosoft.com" -TargetDeliveryDomain "contoso.com" -RemoteCredential (Get-Credential exoip\administrator)
      
      DisplayName Status TargetDatabase
      ----------- ------ --------------
      Jordy Twin  Queued
      

      オンプレミスの資格情報 (RemoteCredential) のパスワードを入力します。

  6. メールボックスの移動状態を取得する

    • Get-MoveRequest コマンドレットを使用して、メールボックスの移動要求の状態を取得します。

      PS C:\> Get-MoveRequest -Identity "Jordy.Twin@contoso.com" | Get-MoveRequestStatistics | ft DisplayName,StatusDetail,TotalMailboxSize,TotalArchiveSize,PercentComplete
      
      DisplayName StatusDetail TotalMailboxSize             TotalArchiveSize PercentComplete
      ----------- ------------ ----------------             ---------------- ---------------
      Jordy Twin  Completed    231.6 MB (242,877,775 bytes) 0 B (0 bytes)                100
      

      メールボックスの移動が完了します。 それ以外の場合、メールボックスの移動要求を完了できない場合は、移動要求を一時停止して再開できます。

完了した移行バッチを削除する次の手順を実装するには、「 完了した移行バッチの削除」を参照してください。