Trying to Migrate a Mailbox to O365

Hello.  I don't know much about scripting or PowerShell but I'm having troubles getting something to work and I'm hoping that someone might help me out.  I am running O365 in a hybrid config with my on premise Exchange 2010 server.  Because I'd like to keep my on premise Exchange server and my local domain controllers, I was told elsewhere that, to create new accounts, I have to create them locally, migrate them up to Office 365 and then assign an O365 license to them.  That is how I have been creating all of my new users and shared mailboxes in the 6 months or so that we have been using O365.  I have begun dabbling with PowerShell and I'd like to find a way to automate the mailbox creation a bit.  I have figured out how to create a new local mailbox and set all necessary properties on it but I would also like to be able to migrate it up to O365 via PowerShell and that's the part that I'm having trouble with.  Here's what I have so far:

New-Mailbox -Name JustaTest -Alias JustaTest -OrganizationalUnit "mydomain.com/My OU" -Database "Mailboxes" -UserPrincipalName JustaTest@mydomainname.com -Shared
Add-MailboxPermission JustaTest -User "MyDomain\Me" -AccessRights FullAccess
Add-ADPermission JustaTest -User "MyDomain\Me" -ExtendedRights Send-As
Set-Mailbox "JustaTest" -EmailAddresses SMTP:JustaTest@mydomain.com,ITB-JustaTest@mydomain.com
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
New-MoveRequest -Identity JustaTest -Remote -RemoteHostName localmailserver.mydomain.com -TargetDeliveryDomain mydomain.mail.onmicrosoft.com -RemoteCredential $Session

The first 4 lines work great but the problems begin when I get to the move request.  I'm getting this when it gets to that part:

C:\Windows\system32>New-MoveRequest -Identity "JustaTest" -Remote -RemoteHostName "localmailserver.mydomain.com" -TargetDeliveryDomain mydomain.mail.onmicrosoft.com -RemoteCredential $Session
Cannot process argument transformation on parameter 'RemoteCredential'. Cannot convert the "System.Management.Automation.Runspaces.PSSession" value of type "Deserialized.System.Management.Automation.Runspaces.PSSession" to type "System.Management.Automation.PSCredential".
    + CategoryInfo          : InvalidData: (:) [New-MoveRequest], ParameterBindin...mationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,New-MoveRequest
    + PSComputerName        : localmailserver.mydomain.com

Any assistance that can be provided would be very much appreciated.
Thanks in advance.
-Chris
April 29th, 2015 3:38pm

Connect to Exchange Online using a Windows PowerShell window run as administrator, not an Exchange Management Console session.  Logging on to Exchange Online causes the cmdlets to overwrite the local cmdlets.  Use two separate windows (unless you use the prefix trick).

Your error is that you're trying to pass a session object as a credential.  It should be -RemoteCredential $OnPremCredential, where $OnPremCredential is an on-premises administrative account.

Free Windows Admin Tool Kit Click here and download it now
April 30th, 2015 7:47am

Hi Chris,

You passing the PSSession object ($Session ) to -RemoteCredential.

Aren't you suppose to Pass the Admin credential object here ($UserCredential )

Incorrect:

New-MoveRequest -Identity "JustaTest" -Remote -RemoteHostName "localmailserver.mydomain.com" -TargetDeliveryDomain mydomain.mail.onmicrosoft.com -RemoteCredential $Session Corrected: New-MoveRequest -Identity "JustaTest" -Remote -RemoteHostName "localmailserver.mydomain.com" -TargetDeliveryDomain mydomain.mail.onmicrosoft.com -RemoteCredential $UserCredential

or

Get-Mailbox -Identity "JustaTest" | New-MoveRequest -Remote -RemoteHostName localmailserver.mydomain.com -RemoteCredential $UserCredential -TargetDeliveryDomain "mydomain.mail.onmicrosoft.com"


How about we validate the below points as well. Like is Get-Mailbox working on remote or not.

After Step 4, the Exchange Online cmdlets are imported into your local Windows PowerShell session as tracked by a progress bar. If you dont receive any errors, you connected successfully.

A quick test is to run an Exchange Online cmdletfor example, Get-Mailboxand see the results.

If you receive errors, check the following requirements:

  • A common problem is an incorrect password. Run the three steps again and pay close attention to the user name and password you enter in Step 1.

  • To help prevent denial-of-service (DoS) attacks, you're limited to three open remote PowerShell connections to your Exchange Online organization.

  • Windows PowerShell needs to be configured to run scripts. You only need to configure this setting once on your computer, not every time you connect. To enable Windows PowerShell to run signed scripts, run the following command in an elevated Windows PowerShell window (a Windows PowerShell window you opened by selecting Run as administrator).

Set-ExecutionPolicy RemoteSigned

  • The account you use to connect to Exchange Online must be enabled for remote Shell. For more information, see Manage remote PowerShell access in Exchange Online.

  • TCP port 80 traffic needs to be open between your local computer and Exchange Online. It's probably open, but its something to consider if your organization has a restrictive Internet access policy.

Best way to learn PowerShell is to track the PS cmdlets used while doing it in EAC. Check out this wiki which should be applicable for O365 as well Exchange Admin Center Cmdlet Logging In Exchange Server 2013 SP1

References:

Hybrid Mailbox moves and EMC changes

Error in Moving Mailboxes to O365

April 30th, 2015 7:53am

Thank you for the in depth reply, Satyajit.  I sincerely appreciate your time.  I have changed the line as you have suggested and tried both the corrected and the alternate method that you have given me and I now get a new error:

C:\Windows\system32>Get-Mailbox -Identity "ITB-YetAnotherTest" | New-MoveRequest -Remote -RemoteHostName hmail.mydomain.com -RemoteCredential $UserCredential -TargetDeliveryDomain "mydomain.mail.onmicrosoft.com"
Target user 'ITB-YetAnotherTest' already has a primary mailbox.
    + CategoryInfo          : InvalidArgument: (mydomain...-YetAnotherTest:MailboxOrMailUserIdParameter) [New-MoveRequest], RecipientTaskException
    + FullyQualifiedErrorId : 4E11596C,Microsoft.Exchange.Management.RecipientTasks.NewMoveRequest
    + PSComputerName        : hmail.mydomain.com

Dirsync had not yet occurred so I'm not sure what's going on.

Please excuse my ignorance as I'm not really too sure what I'm doing.  :-)  For connecting to O365, I just copied and pasted the relevant lines from this article but it sounds like that's not what I'm supposed to be using in my specific case.  All of the other steps in my process are working fine and when I run Get-Mailbox, it returns the test mailbox that I am creating with this script so I believe that my connection is OK.  

Thanks again for your assistance.  
-Chris

Free Windows Admin Tool Kit Click here and download it now
May 1st, 2015 11:33am

The command is saying that the account you're trying to move to already has a mailbox. You'll need to disable that mailbox first.  Copy any content out of it first if you need to.

May 1st, 2015 12:33pm

But it's a brand new account, created with this script only a few seconds before it got to the mailbox migration part.  
Free Windows Admin Tool Kit Click here and download it now
May 1st, 2015 12:38pm

What can I say?

Run Get-Recipient to see what type of recipient the user is.

May 1st, 2015 12:51pm

It's Recipient Type UserMailbox.  
Free Windows Admin Tool Kit Click here and download it now
May 1st, 2015 1:16pm

My understanding of how it should work is that I create a local mailbox and then migrate it up to O365.  Is the error telling me that the remote mailbox already exists or the local mailbox already exists?  The local mailbox exists because the script just created it so I don't get why it's having a problem with that.

Am I misunderstanding the process?

Thanks.

May 1st, 2015 1:18pm

Normally we build the online mailbox and sync down. You are trying to sync up so the online mailbox should not exist. Start by renaming the online mailbox and try again. If the online mailbox has mail then you can copy it to the newly created onlin
Free Windows Admin Tool Kit Click here and download it now
May 1st, 2015 3:26pm

Since I've been working on this, I've just been creating test accounts and deleting them a few minutes after creating them so nothing is being used and none of them have any mail in them.  It never gets to the point where there is an online mailbox and this is what is puzzling me about the latest error.  

I'm certainly open to creating the mailbox online and syncing it down.  I assume the commands will be the same, but I have to log on to O365 in the script first?

Thanks.

May 1st, 2015 4:06pm

The O365 provisioning forum has some good links to different ways to set up initial hybrid  mailboxes.  You should review their posts.  It is actually quite easy and they have a number of PS scripts.  The Gallery here also has some scripts.

Free Windows Admin Tool Kit Click here and download it now
May 1st, 2015 4:44pm

You can do that, but if you're in hybrid, it's much easier to create a new remote mailbox.

New-RemoteMailbox

https://technet.microsoft.com/en-us/library/ff607480

May 2nd, 2015 1:34am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics