The error The operation couldn't be performed because object 'mydomain.com/Adaxes/adaxes resource mb3' couldn't be found on 'DC5.mydomain.com'. is caused by delays in replication, and inserting Start-Sleep commands that give some time for replication to complete is a good choice in this case. However the time interval that you chose, 60 seconds, is, probably, too much. We reduced it to 10 seconds, which should be quite enough.
The error Cannot open mailbox /o=my org/ou=Exchange Administrative Group (FYDIB0LF23SPDLT)/cn=Configuration/cn=Servers/cn=MBX1/cn=Microsoft System Attendant. is also caused by replication. The thing is that the Set-CalendarProcessing cmdlet uses the nearest available DC to write information to Active Directory, and that specific DC may not have enough time to replicate information that a mailbox has already been created for the user.To remedy the issue, we inserted one more Start-Sleep command before calling this cmdlet.
If any of these errors still persist, try increasing the time intervals for the Start-Sleep commands.
Here's our modified version of the script:
$exchangeServer = "ExchangeServer.com" # TODO: Modify me
$usersIdentity = ($Context.TargetObject.Get("adm-CustomAttributeText8")).Split(',')
$Context.LogMessage("No users to grant Delegates permissions to", "Error") # TODO: modify me
$usersIdentity = $NULL
# Disable the Target User
$targetUser = $Context.BindToObject($Context.TargetObject.AdsPath)
$targetUser.AccountDisabled = $True
$domainName = $Context.GetObjectDomain("%distinguishedName%")
$rootDSE = $Context.BindToObject("Adaxes://$domainName/rootDSE")
$domainControllerFQDN = $rootDSE.Get("dnsHostName")
Start-Sleep -s 10
$session = new-pssession -connectionURI "http://$exchangeServer/powershell" -ConfigurationName Microsoft.Exchange
Import-PSSession -session $session
Enable-Mailbox -Identity '%distinguishedName%' -DomainController $domainControllerFQDN -Room
Start-Sleep -s 30
if ($usersIdentity -ne $NULL)
for ($i = 0; $i -lt $usersIdentity.Length; $i++)
$usersIdentity[$i] = $usersIdentity[$i].Trim()
Set-CalendarProcessing -Identity '%distinguishedName%' -ResourceDelegates $usersIdentity -DomainController $domainControllerFQDN
Remove-PSSession -Session $session