Greetings!
Goal: Migrate/Move Mailboxes from one Domain to another Domain.
I'm attempting to understand the process that would have to occur for mailbox moves with the following in mind:
DomainA - 2K8R2 Operating Level; Exchange 2010 SP1; Powershell v1
DomainB - 2K8R2; Exchange 2010 SP1; Powershell v1
No ACTIVE communication between DomainA and DomainB
User accounts will be imported into DomainB before mailbox move occurs.
I don't have a testbed for any of this so I have to hammer out the process before actually DOING the process. I've looked at MS site on it but am still having a hard time understanding how it applies to my environment. I'm tasked with the entire domain migration and am not entirely versed in Exchange enough to be comfortable to read the tech articles and apply them correctly.
http://technet.microsoft.com/en-us/library/dd351280.aspx
For those referencing this forum post let me include the processes I have started for this:
NOTE - ExecutionPolicy must be set to at least Remote Signed to perform any tasking procedures.
NOTE 2- I have NOT performed the Export all mailboxes code yet. I performed the single mailbox export but am confident it will work. Also, I have not ran this specific code as I had to retype it on another system for testing, if there's any typos please let me know so that I can fix them :) As always, take care when running ANY code in ANY production environment.
1. Get current mailbox sizes:
##############
Get-MailboxStatistics -Server "SERVER" | Where {$_.ObjectClass -eq "Mailbox" | Sort-Object TotalItemSize -Descending | ft @{label="User";expression{$_.DisplayName}},@{label="Total Size (MB)";expression={$_.TotalItemSize.Value.ToMB()} -auto >> "C:\Temp\Mailbox_Size.txt"
$a = Get-Date
$month = $a.month
$day = $a.day
$year = $a.year
$location = "C:\Temp\"
$BASE = "mailbox_size.txt"
$filename = $location+"$month"+"-"+"$day"+"-"+"$year"+"-"+$BASE
$oldfile = $location+$BASE
Rename-Item $oldfile $filename
####################################
2. Grant Proper Permissions for Import/Export (never want to mess without a safety net so Export all mailboxes to PSTs first!!) - Have to restart the powershell management shell after setting so that it takes. This can be set for Users and for Groups.
####################################
$user = Read-Host "Please enter in a user to assign the permissions to"
New-ManagementRoleAssignment -Role "Mailbox Import Export" -User $user
#####################################
3. Export mailboxes to PST. This can be done on the current in USE mailbox as well as the Archive Mailbox.
Here is my MENU driven code for the process (to be ran on mailbox server):
##################################################
#Date: 02/04/2012
#Exchange Powershell to export User Mailboxes
.'C:\Program Files\Microsoft\Exchange Server\V14\Bin\RemoteExchange.ps1'
Connect-ExchangeServer -Auto
[String] $menu = @'
Select an Option from the List Below:
Execution Policy Options
1. View Execution Policy
2. Set Execution Policy to Unrestricted
3. Set Execution Policy to RemoteSigned
4. Set Execution Policy to Restricted
Exchange 2010 Mailbox Options
5. View Role "Mailbox Import Export" Assignment
6. Add User to "Mailbox Import Export" Role Assignment
7. Get Mailbox Sizes
8. Export Specific User Mailbox to PST
9. Export All Mailboxes to PSTs
10. Export All Archive Mailboxes to PSTs
11. Check All Export Requests to PSTs
12. Check Queued Export Requests
13. Check Pending Export Requests
14. Check Completed Export Requests
15. Check Failed Export Requests
16. Export Mailboxes to CSV
17. Enable Mailboxes from CSV
20. Exit
Select an Option...:
'@
#Create Functions to be called with Menu correlations below
Function ExecutionPolicyUnrestricted {
Set-ExecutionPolicy Unrestricted
}
Function ExecutionPolicyRestricted {
Set-ExecutionPolicy Restricted
}
Function ExectuionPolicyRemote {
Set-ExecutionPoly RemoteSigned
}
Function ExecutionPolicyView {
$Policy = Get-ExecutionPolicy
$a = New-Object -comObject wscript.shell
$b = $a.popup("The Execution Policy is currently set to: $Policy",0,"Execution Policy Setting",1)
}
Function ExportSingleMailbox {
$user = Read-Host "Enter User mailbox to export (ex: SmithB)"
$a = New-Object -comObject wscript.shell
$b = $a.popup("Path must be UNC path and Exchange Trusted Subset must have R/W",0,"Permissions",1)
$path = Read-host "Please enter in Path .pst"
New-MailboxExportRequest -Mailbox "$user" -FilePath "$path"
}
Function ExportMailboxes {
$mailboxes = @()
$mailboxes = Get-Mailbox
ForEach ($mailbox in $mailboxes) {
New-MailboxExportRequest -Mailbox $mailbox -FilePath "\\share\PSTs\$mailbox.pst"
}
}
Function ExportArchives {
$path = Read-Host "Enter Path for CSV (ex: \\SHARE\PST\): "
$mailboxes = @()
$mailboxes = Get-Mailbox
ForEach ($mailbox in $mailboxes) {
New-MailboxExportRequest -Mailbox $mailbox -FilePath "\\SHARE\PSTs\$mailbox.pst" -IsArchive
}
}
Function CheckStatus {
Get-MailboxExportRequest | Get-MailboxExportRequestStatistics
}
Function CheckCompleted {
Get-MailboxExportRequest | Where {$_.status -eq "Completed"}
}
Function CheckPending {
Get-MailboxExportRequest | Where {$_.status -eq "InProgress"}
}
Function CheckQueued {
Get-MailboxExportRequest | Where {$_.status -eq "Queued"}
}
Function CheckFailed {
Get-MailboxExportRequest | Where {$_.status -eq "Failed"}
}
Function ExportCSV {
$path = Read-Host "Enter Path (ex: C:\ExportMailboxes.csv): "
Get-Mailbox -ResultSize Unlimited | Select Identity,RetentionPolicy,Database | Export-CSV "$path"
$a = New-Object -comObject wscript.shell
$b = $a.popup("Do F/R on Identity in CSV to match new domain",0,"General",1)
}
Function EnableMailboxes {
$path = Read-Host "Enter Path to Export CSV: "
$mailbox = Import-csv "$path"
ForEach ($mailbox in $mailbox) {
Enable-Mailbox -Identity $mailbox.Identity -RetentionPolicy $mailbox.RetentionPolicy -Database $mailbox.Database
}
}
Function GetMailboxSizes {
Get-MailboxStatistics -Server "SERVER" | Where {$_.ObjectClass -eq "Mailbox"} | Sort-Object TotalItemSize -Descending | ft @{label="User";expression={$_.DisplayName}},@{label="Total Size (MB)";expression={$_.TotalItemSize.Value.ToMB()}}
-auto >> "C:\Temp\Mailbox_Size.txt"
$a = Get-Date
$month = $a.month
$day = $a.day
$year = $a.year
$location = "C:\Temp\"
$BASE = "mailbox_size.txt"
$filename = $location+"$month"+"-"+"$day"+"-"+"$year"+"-"+$BASE
$oldfile = $location+$BASE
Rename-Item $oldfile $filename
}
Function ViewRoleAssignment {
Get-ManagementRoleAssignment -Role "Mailbox Import Export"
}
Function SetRoleAssignment {
$user = Read-Host "Please enter in a user to assign the permissions to"
New-ManagementRoleAssignment -Role "Mailbox Import Export" -User $user
$a = New-Object -comObject wscript.shell
$b = $a.popup("Restart Powershell and invoke script for permissions to be set.",0,"General",1)
}
#Correlate Menu options to functions/code
Do
{
$opt = Read-Host $menu
switch ($opt)
{
1 { #View Execution Policy
ExecutionPolicyView
}
2 { #Set Execution Policy Unrestricted
ExecutionPolicyUnrestricted
}
3 { #Set Execution Policy RemoteSigned
ExecutionPolicyRemoteSigned
}
4 { #Set Execution Policy Retristed
ExecutionPolicyRestricted
}
5 {
ViewRoleAssignment
}
6 {
SetRoleAssignment
}
7{
GetMailboxSizes
}
8 {
ExportSingleMailbox
}
9 {
ExportMailboxes
}
10 {
ExportArchives
}
11 {
CheckStatus
}
12 {
CheckQueued
}
13 {
CheckPending
}
14 {
CheckCompleted
}
15 {
CheckFailed
}
16 {
ExportCSV
}
17 {
EnableMailboxes
}
20 {
Exit
}
}
}
While ($opt -ne 20)
Lori