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 }
}