I have a script that adds a mailbox permission to all users, but it is getting throttled after switching to the new app registration authentication. Is there any way to prevent this?

Fail to create runspace because you have exceeded your budget to create runspace. Please wait for 26 seconds.

try
{
    # Get the object ID in Office 365
    $objectId = [Guid]$Context.TargetObject.Get("adm-O365ObjectId")
}
catch
{
    return # The user doesn't have an Office 365 account
}

try
{
$session = $Context.CloudServices.CreateExchangeOnlinePSSession()
Import-PSSession $session -AllowClobber -DisableNameChecking -CommandName "Add-MailboxPermission"

 # Change mailbox type
    Add-MailboxPermission $objectId.ToString() -User "company administrator" -AccessRights 'FullAccess'
}
finally
{
    # Close the remote session and release resources
    if ($session) { Remove-PSSession $session }
}
by (540 points)

1 Answer

by (307k points)
0 votes

Hello,

This behaviour is expected as the script establishes a new connection for each user. The issue is not related to Adaxes and is devoted to the limits of Exchange Online. To achieve the desired, you need to use a single connection to delegate all the permissions.

Unfortunately, we are currently very limited in resources and have no possibility to write and test the updated script for you. Should you, have issues doing it yourself, we encourage you to address the request to our consulting partners that provide professional services: https://www.adaxes.com/purchase_consultants.htm. Sorry for the inconvenience and thank you for your understanding.

Related questions

I need to connect to Exchange Online using specific service principal, but I am getting error I am trying to authenticate via Connect-ExchangeOnline -AccessToken $token - ... btw aka 3.8.0 version of the ExchangeOnlineManagement module is used automatically.

asked 6 days ago by KIT (1.0k points)
0 votes
1 answer

Hi, when I enable a license for Exchange Online for a user I get the following warning: Here are the current settings for creating a remote ... : InvalidOperation: (:) [], RuntimeException     + FullyQualifiedErrorId : PropertyAssignmentException

asked 6 days ago by Allister (70 points)
0 votes
1 answer

Hello, We've previously had assistance in implementing a method to transfer email addresses to a specified user via a powershell script for our on-prem Exchange. This has ... $user.SetInfo() Please let me know if you require more clarification. Regards, Josh

asked Aug 25 by jtop (720 points)
0 votes
1 answer

Unable to select the option "Hide from exchange addres list" from shared mailbox that is being managed via Adaxes Getting this error The operation on mailbox "6e481282- ... . This action should be performed on the object in your on-premises organization.

asked Apr 17 by sctheva (20 points)
0 votes
1 answer

After creating a user, I want to create a mailbox that is visible both on-premises and in Exchange Online (remote mailbox). The presence in on-premises Exchange is required ... migration is completed. The groups the user is being added to are license groups.

asked Oct 21, 2024 by Cas (200 points)
0 votes
1 answer