浅谈Exchange混合部署(六)--使用PoweShell来迁移邮箱

16 篇文章 1 订阅
15 篇文章 0 订阅

相比于使用图形化界面,PowerShell确实麻烦了一些,但是我们可以看到一些图形化界面给不到的信息。


适当替换一些用户名,域名部分,代码不是为了一次性运行,主要是为了学习使用PowerShell来做迁移的目的

连接到Exchange Online PowerShell

# Set exetution policy to remotesigned

Set-ExecutionPolicy RemoteSigned

# Connect to Exchange Online PowerShell

$UserCredential = Get-Credential

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

Import-PSSession $Session

创建迁移终结点,使用自动发现记录的情况:

# Create Migration Endpoint. To do so, first enter the following and then specify the credentials of an account that is member of the 揙rganization Management?role group in the on-premises Active Directory.
# Replace the paramater for -Name, this Name parameter will be used when create new migration batch.

# For using Autodiscover
$MigrationEndpoint = New-MigrationEndpoint -Name Endpoint1 -ExchangeRemoteMove -Autodiscover -EmailAddress tonysmith@contoso.com -Credentials (Get-Credential contoso\tonysmith)
Write-Host $MigrationEndpoint

# Example New-MigrationEndpoint -Name TestMig -ExchangeRemoteMove -Autodiscover -EmailAddress robinj@robinrock.com -Credential (Get-Credential robinrock\robinj)

如果报错提示无法使用自动发现记录,那么手动指定服务器公网FQDN:

# If getting error saying Autodisvoer not work, manually specify the server name
$MigrationEndpoint = New-MigrationEndpoint -Name Endpoint2 -ExchangeRemoteMove -RemoteServer MRSServer.contoso.com -Credentials (Get-Credential Contoso.com\Administrator)
Write-Host $MigrationEndpoint

# Example New-MigrationEndpoint -Name TestMig -ExchangeRemoteMove -RemoteServer mail.robinrock.com -Credential (Get-Credential robinrock\robinj)

创建迁移批次:

<# This Section is for Creating an Migration Batch#>

# Replace the -Name parameter with your own choice, and replace the -SouceEndpoint parameter with the name of the Endpoint you create in the previous step. The TargerDeliveryDomain will be provided by the customer in the Migration Questionnaire
$ MigrationBatch = New-MigrationBatch -Name MigrationBatch1 -SourceEndpoint TestMig -TargetDeliveryDomain robinrock.mail.onmicrosoft.com -CSVData ([System.IO.File]::ReadAllBytes(揅:\MigrationBatch1.csv?)
Write-Host $MigrationBatch

# The MigrationBatch1.csv file must be create in the following structure and save as .csv file
#	"EmailAddress"
#	"RobinRock365TestMbx1@robinrock.com"
#	"RobinRock365TestMbx2@robinrock.com"
#	"RobinRock365TestMbx3@robinrock.com"
#	"RobinRock365TestMbx10@robinrock.com"

开始迁移:

# Now you can start this migraion batch by running the following command, specify the paramater for the -Identity
Start-MigrationBatch -Identity MigrationBatch1

# The above command is for SWRC's replication part, meaning it will complete 95% of the migraion, as show below:
# run the following command to retrive the progress:
get-moverequest | get-moverequeststatistics

#	PS C:\Users\v-jiaxia> get-moverequest | get-moverequeststatistics
#	
#	DisplayName          StatusDetail                   TotalMailboxSize               TotalArchiveSize PercentComplete
#	-----------          ------------                   ----------------               ---------------- ---------------
#	RobinRock365 TestMbx3  Synced                         2.604 KB (2,666 bytes)                          95
#	RobinRock365 TestMbx2  Synced                         2.604 KB (2,666 bytes)                          95
#	RobinRock365 TestMbx1  Synced                         2.604 KB (2,666 bytes)                          95
#	RobinRock365 TestMbx10 Synced                         2.611 KB (2,674 bytes)                          95

完成批次:

# To complete the migration, we need to set the completion date and time, the time will be following UTC time, execute the following command:
gc .\file.txt | Set-MoveRequest -CompleteAfter "September 19, 2017 2:55:00 PM"

# the file.txt need to in the below format
# 
#	RobinRock365TestMbx1@robinrock.com
#	RobinRock365TestMbx2@robinrock.com
#	RobinRock365TestMbx3@robinrock.com
#	RobinRock365TestMbx10@robinrock.com

监视迁移进度的命令:

# Now you can monitor the process using the following command:
Get-MigrationUser 
Get-MigrationBatch

# Once hit the completion time, you will have the result like below:
#	DisplayName     StatusDetail TotalMailboxSize               TotalArchiveSize PercentComplete
#	-----------     ------------ ----------------               ---------------- ---------------
#	RobinRock365 T... Completed    2.604 KB (2,666 bytes)                          100
#	RobinRock365 T... Completed    2.604 KB (2,666 bytes)                          100
#	RobinRock365 T... Completed    2.604 KB (2,666 bytes)                          100
#	RobinRock365 T... Completed    2.611 KB (2,674 bytes)                          100

查看单个用户的迁移情况

# You can check indivial user by executing:
get-migrationuser RobinRock65TestMbx1@robinrock.com | get-migrationuserstatistics

#Get following result
#	Identity                                  Batch                          Status                    Items Synced     Items Skipped
#	--------                                  -----                          ------                    ------------     -------------
#	RobinRock365TestMbx1@sunlandgroup.com.au  Test                           Completed                 3                0
#If you notice the Migration failed, please run command below get detailed error:
get-migrationuserstatistics -identity RobinRock365TestMbx1@robinrock.com -includereport | FL status,error,report

完成

Write-Host "Script Complete!"
<#Script Finish Here#>

这里我们可以看到邮箱在迁移过程中先同步了95%,然后指定时间去完成了最后的5%

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值