0 votes


I recently set up a business role per a post in this thread that creates an on-prem shared mailbox and then moves that mailbox to O365. The issue is that the powershell script to move to O365 keeps erroring out with the following:

Connecting to remote server failed with the following error message: WS-Management cannot process the request. The operation failed because of an HTTP error. HTTP error 12152: server returned an invalid or unrecognized response.

I pulled the script straight from Adaxes support so not sure where it went wrong. The script I grabbed is below (took out variables specific to our environment):

Taken from this forum post: Create user mailbox in Office 365?

# Credentials of a user who has sufficient permissions to provision users for Office 365
$office365AdminName = "removed_for_post" # TODO: modify me
$office365AdminPassword = ConvertTo-SecureString -AsPlainText -Force -String "removed_for_post" # TODO: modify me

$office365DeliveryDomain = "removed_for_post" # TODO: modify me

$office365Credentials = New-Object -TypeName System.Management.Automation.PSCredential($office365AdminName, $office365AdminPassword)

$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://ps.outlook.com/powershell/" -Credential $office365Credentials -Authentication Basic -AllowRedirection
Import-PSSession $session

# Credentials of the local Exchange domain administrator
$localAdminName = $Context.RunAs.UserName + "@" + $Context.RunAs.Domain
$localAdminPassword = ConvertTo-SecureString -AsPlainText -Force -String $Context.RunAs.Password 
$localAdminCredentials = New-Object -TypeName System.Management.Automation.PSCredential($localAdminName, $localAdminPassword)

$localDomain = $Context.GetObjectDomain("%distinguishedName%")

    $result = New-MoveRequest -Identity "%username%" -Remote -RemoteHostName $localDomain -TargetDeliveryDomain $office365DeliveryDomain -RemoteCredential $localAdminCredentials -ErrorAction Stop
    $Context.LogMessage($_.Exception.Message, "Error")

Remove-PSSession $Session

if ($result -ne $NULL)
    $Context.LogMessage("Mailbox move request created successfully. Check Exchange logs for details." , "Information")
by (480 points)

Nevermind, this has been RESOLVED. For whatever reason, in our environment, the call to O365 will error out the first try every time. We put a loop in to try it twice and it worked.

Please log in or register to answer this question.

Related questions

0 votes
1 answer

Hello, We have an exchange server in a separate forest. When we create the mailbox using a business rule after user creation, the mailbox creates ok. After the user ... multi-forest environment and it made no difference. Thanks for any help you can provide.

asked Nov 2, 2018 by Jasonmh (540 points)
0 votes
1 answer

I am having an issue running a powershell script through Adaxes. I am trying to have this run as a business rule when ... $optoffice.DisabledServicePlans = "ONEDRIVESTANDARD" Set-MsolUserLicense -UserPrincipalName %userPrincipalName% -LicenseOptions $optOffice

asked Mar 2, 2015 by malsobrook (50 points)
0 votes
1 answer

Receive "Index operation failed; the array index evaluated to null. Stack trace: at <ScriptBlock>, <No file>: line 104>" and "Index operation failed; the ... $GroupName, $GroupDN." } } #foreach write-output "" Write-Output "" Stop-Transcript

asked Apr 14 by jbahou (20 points)
0 votes
1 answer

Hi Team! I'm currently looking for a solution to create an exchange mailbox on-premise, sync it to Office 365 and assign the license in one business rule. I didn't ... solution from our side? Please let me know how to configure this. Best Regards Marco Jandl

asked Apr 6 by marco_jandl (60 points)
0 votes
1 answer

We are using Adaxes to manage multiple domains. upwards of 10 domains. There is no trust between the domains. The are all separate stand alone. We want to setup a scheduled ... domain has an Adaxes service account setup and that is what i would want to use.

asked Sep 14, 2020 by gt_111 (20 points)
2,779 questions
2,512 answers
26,511 users