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
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.
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:
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
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.
What can I say?
Run Get-Recipient to see what type of recipient the user is.
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.
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.
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.
You can do that, but if you're in hybrid, it's much easier to create a new remote mailbox.
New-RemoteMailbox