Exchange Server - powershell script to move mailboxes across organization in bulk

Asked By Amy
28-Jun-07 06:16 PM
I found a beautiful script http://www.exchangeninjas.com/MoveMBsToTargetMD
to move mailboxes in an Exchange 2007 organization using a .csv file for
input.  I would like to do the same thing, but move these mailboxes from one
Exchange organization (2003) to another Exchange organization (2007).  The
regular command to do this from a command line looks like this:

move-mailbox -TargetDatabase "Mercury\First Storage Group\Mailbox
Database" -identity user1 -GlobalCatalog
$SourceCredential -TargetForestCredential $TargetCredential

I would like to see if anyone has a way that I can run this from a .ps1
script but use a .csv file as input for the -Identity parameter.  Any help
would be greatly appreciated!
MoveMBsToTargetMD
(1)
NTAccountOU
(1)
SourceForestGlobalCatalog
(1)
TargetForestCredential
(1)
SourceForestCredential
(1)
TargetOU
(1)
TargetCredential
(1)
SourceCredential
(1)
  Bharat Suneja [MVP] replied...
28-Jun-07 09:08 PM
CSV (MoveMailboxes.csv) fields:
Username, TargetDatabase, TargetOU

(You can leave out the TargetDatabase and TargetOU if all moved mailboxes
will be in the same OU and on the same target Store... and use those
references in the command instead of having them in the CSV).

$SourceCredential = Read-Host "Enter Source Forest
Credentials" -AsSecureString
$TargetCredential = Read-Host "Enter Target Forest
Credentials" -AsSecureString

Import-CSV MoveMailboxes.csv | foreach {Move-Mailbox -Identity
$_.Username -TargetDatabase $_.TargetDatabase -NTAccountOU
_.TargetOU  -SourceForestGlobalCatalog "mctdc1.test.net" -GlobalCatalog
$SourceCredential -TargetForestCredential $TargetCredential}

--
Bharat Suneja
MVP - Exchange
www.zenprise.com
NEW blog location:
exchangepedia.com/blog
------------------------------
  Amy replied...
28-Jun-07 10:41 PM
Thank you so much Bharat,  I have something very similar to this but mine
isnt as elegant as yours, as I didnt allow for the SourceCredential and
TargetCredential - I was running those manually inside the shell before I
spun off my script.... my one problem, and I think this script here will
have it too... how do you pipe the Yes at the end of each mailbox that it is
going to move?  I have tried every trick I know from my batch scripting....

Thanks

amy
Create New Account
help
Mailbox -TargetDatabase "Target Server \ First Storage Group \ Mailbox Database" -Identity john -GlobalCatalog GC01.fabrikam.com -SourceForestGlobalCatalog GC02.contoso.com -NTAccountOU $SourceCredential -TargetForestCredential $TargetCredential everything went well. but i get the following error "THE SPECIFIED DATABASE pls can anyone help with a workaround this issue? Thanks Adamu Garba Exchange Setup Discussions NTAccountOU (1) SourceForestGlobalCatalog (1) SourceForestCredential (1) TargetForestCredential (1) TargetCredential (1) SourceCredential (1) TargetDatabase (1) GlobalCatalog (1) Pls Guys
gmc-w.gaylemfg.com' -Credential $s -database 'BROWN \ priv1' | move-mailbox -TargetDatabase 'MAIL \ Mailbox Database' -SourceForestGlobalCatalog 'BROWN.gmc-w.gaylemfg.com' -GlobalCatalog 'adw.gmcx .com' -DomainController 'adw.gmcx.com' -NTAccountOU 'OU = Users, OU = Woodland, DC = gmcx, DC = com' -IgnorePolicyMatch -SourceForestCredential $s -TargetForestCreden tial $t Exchange gmc-w.gaylemfg.com' -Credential $s -database 'BROWN \ priv1' | move-mailbox -TargetDatabase 'MAIL \ Mailbox Database' -SourceForestGlobalCatalog 'BROWN.gmc-w.gaylemfg.com' -GlobalCatalog 'adw.gmcx.com' -DomainController 'adw.gmcx.com' -NTAccountOU 'OU = Users, OU = Woodland, DC = gmcx, DC = com' -IgnorePolicyMatch -SourceForestCredential $s -TargetForestCredential $t Let me you can run: get-mailbox -DomainController BROWN.gmc-w.gaylemfg.com -Credential $c | move-mailbox -SourceForestGlobalCatalog BROWN.gmc-w.gaylemfg.com -GlobalCatalog adw.gmcx.com -DomainController adw.gmcx.com -NTAccountOU 'OU = Users, OU = Woodland, DC = gmcx, DC = com' -IgnorePolicyMatch -SourceForestCredential $c -TargetForestCredential $t Sorry, you
Mailbox -TargetDatabase "Target Server \ First Storage Group \ Mailbox Database" -Identity john -GlobalCatalog GC01.fabrikam.com -SourceForestGlobalCatalog GC02.contoso.com -NTAccountOU -TargetForestCredential $TargetCredential After the move completed, everything looks great: Email addresses and permissions are all Admin Discussions Exchange Server 2003 (1) Exchange Server 2007 (1) Microsoft Exchange (1) Outlook (1) NTAccountOU (1) SourceForestGlobalCatalog (1) MigStubqvMR (1) MigstubXXXX (1) I am not sure what version of outlook you have Mailbox -TargetDatabase "Target Server \ First Storage Group \ Mailbox Database" -Identity john -GlobalCatalog GC01.fabrikam.com -SourceForestGlobalCatalog GC02.contoso.com -NTAccountOU -TargetForestCredential $TargetCredential After the move completed, everything looks great: Email addresses and permissions are all