0 votes

Hi,

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%")

try
{
    $result = New-MoveRequest -Identity "%username%" -Remote -RemoteHostName $localDomain -TargetDeliveryDomain $office365DeliveryDomain -RemoteCredential $localAdminCredentials -ErrorAction Stop
}
catch
{
    $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)
0

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

Trying to create a custom command to run a powershell script, but I keep getting an error saying it can't find the file or path supplied for launching powershell. ... and I can launch powershell from this location using Command Prompt. Am I missing something?

asked Oct 24 by cstaub (100 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

Hi there, i've a custom command with multiple powershell scripts (for clearance reasons). If for example the frist script produces an error i Write an Error but the next ... tried with an simple exit 1; I only Write-Errors on issues. Kind regards, Constantin

asked Jul 23, 2021 by Constey (190 points)
0 votes
1 answer

Hi All, I'm trying to use the powershell script provided here: https://www.adaxes.com/script-repository/move-mailbox-tofrom-microsoft-365-s579.htm Unfortuntately when executing ... credentials but I do not know why this error is happening. Thanks in advance

asked Aug 1, 2023 by curtisa (290 points)
3,538 questions
3,229 answers
8,224 comments
547,747 users