My current Exchange environment is a hybrid configuration of Office 365, Exchange 2013 hybrid, and Exchange 2007 on-premise.
I have a script responsible for enabling remote mailboxes and assigning O365 licenses to a list of users; essentially provisioning users an O365 mailbox. This script runs every hour through a defined scheduled task in the Task Scheduler.
The script is proven to work but will intermittently throw an error on some days: "Could not find any available Global Catalog in forest root.xyz.com"
Here are the nuances of the error when it does occur:
- It will only throw the error when the script is run via scheduled task - the script will work fine if executed from the command line
- The error occurs when "Enable-RemoteMailbox" or "Get-RemoteMailbox" is called.
- The same error will occur with ANY script that calls "Enable-RemoteMailbox" or "Get-RemoteMailbox" and is ran via scheduled task - even when the RemoteMailbox cmdlet was the only line in the script
Here is the output and error when Get-RemoteMailbox -verbose is ran:
VERBOSE: [15:49:52.474 GMT] Get-RemoteMailbox : Active Directory session
settings for 'Get-RemoteMailbox' are: View Entire Forest: 'True',
VERBOSE: [15:49:52.489 GMT]
Get-RemoteMailbox : Runspace context: Executing
user: ,
Executing user organization: ,
Current organization: ,
RBAC-enabled:Disabled.
VERBOSE: [15:49:52.489 GMT] Get-RemoteMailbox : Beginning processing
VERBOSE: [15:49:52.521 GMT] Get-RemoteMailbox : Current ScopeSet is: {
Recipient Read Scope: {{, }},
Recipient Write Scopes: {{, }}, Configuration Read Scope: {{, }},
Configuration Write Scope(s): {{, }, },
Exclusive Recipient Scope(s): {},
Exclusive Configuration Scope(s): {} }
VERBOSE: [15:49:52.521 GMT] Get-RemoteMailbox : Resolved current organization: .
VERBOSE: [15:49:52.521 GMT] Get-RemoteMailbox : Searching objects "abose" of type "ADUser" under the root "$null".
VERBOSE: [15:49:52.536 GMT] Get-RemoteMailbox : Previous operation run on global catalog server 'evw-xyzdc-p02.ad.xyz.com'.
Get-RemoteMailbox : Could not find any available Global Catalog in forest root.xyz.com.
At C:\IDM_In\Scripts\MinimalTest.ps1:42 char:14
+ $abose = Get-RemoteMailbox 'abose' -verbose
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-RemoteMailbox], ADTransientException
+ FullyQualifiedErrorId : E421EF0B,Microsoft.Exchange.Management.RecipientTasks.GetRemoteMailbox
VERBOSE: [15:49:52.567 GMT] Get-RemoteMailbox : Ending processing
What could be the cause of this intermittent error?
Thanks for any help