David-Barrett-MS / PowerShell-EWS-Scripts

A collection of PowerShell scripts that use EWS to perform actions against Exchange mailboxes
MIT License
119 stars 13 forks source link

Autodiscover service couldn't be located error (MergeMailboxFolder) #9

Closed luchok closed 1 year ago

luchok commented 2 years ago

I have used the script in the past to move emails from archive to inbox in the past along with a batching script to perform the action on multiple accounts in the past. I tried again today and getting the following errors using the script:

The mailbox@contoso.com is the account that we are trying to move emails from archive to inbox, and administrator.O365 is the account that has full access to this mailbox.

PS C:\ArchiveMerge>> .\Merge-MailboxFolder.ps1 -SourceMailbox mailbox@contoso.com -SourceArchive -TargetMailbox
 mailbox@contoso.com -ProcessSubfolders -MergeFolderList @{"WellKnownFolderName.Inbox"= "Inbox"} -AllowInsecureRedi
rection -Verbose -Credential (Get-Credential)

cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
Credential

Security warning
Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your
computer. If you trust this script, use the Unblock-File cmdlet to allow the script to run without this warning
message. Do you want to run C:\EOL-ArchiveMerge\Merge-MailboxFolder.ps1?
[D] Do not run  [R] Run once  [S] Suspend  [?] Help (default is "D"): R
Merge-MailboxFolder.ps1 version 1.2.2 starting
VERBOSE: Loading Microsoft.Exchange.WebServices.dll vSystem.Object[] found at: System.Object[]
Using EWS Managed API found at: C:\Program Files (x86)\Microsoft Office\root\Office16\ADDINS\Microsoft Power Query for E
xcel Integrated\bin\Microsoft.Exchange.WebServices.dll

Processing mailbox mailbox@contoso.com
VERBOSE: Applying given credentials: administrator.O365@CONTOSO.onmicrosoft.com
VERBOSE: Performing autodiscover for mailbox@contoso.com
mailbox@contoso.com : error occurred during autodiscover: Exception calling "AutodiscoverUrl" with "2" argument(s):
 "The Autodiscover service couldn't be located."
Failed to connect to source mailbox

The last version I was using was 1.1.5 and I believe it still worked about 2 months ago. Any assistance in finding the issue would be appreciated. I am not very well versed in PS scripting.

Thank you for the help and the script.

David-Barrett-MS commented 2 years ago

Autodiscover is failing here, which implies that either it isn't set up correctly or the credentials are wrong. For Office 365, you can bypass autodiscover completely as it isn't required - just use the -Office365 parameter to specify the mailbox is in Office 365.