0 votes

Recently, Microsoft deprecated use of the remote PS sessions using version 1. We have since converted all of our scripts to version 2, but our nightly staff changes that used to process without issue are now failing on several tasks with the error : Your app has been throttled by ADD dude to too many requests.

Is there a way I need to modify the following code to allow all processes to complete properly as they did when using version 1? Thanks

$groupNames = @("SG_EXAMPLE")

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

try
{

    # Connect to Exchange Online
    Connect-ExchangeOnline -Credential $Context.GetOffice365Credential()

    foreach ($groupName in $groupNames)
    {
        # Add user to group
        try
        {
            Add-DistributionGroupMember $groupName -Member $objectId.ToString() -BypassSecurityGroupManagerCheck -ErrorAction Stop
        }
        catch
        {
            $Context.LogMessage("An error occurred while adding the user to group $groupName. Error: " + $_.Exception.Message, "Warning")
        }
    }
}
finally
{
    # Close the remote session and release resources
    Disconnect-ExchangeOnline -Confirm:$false
}
by (80 points)

1 Answer

0 votes
by (272k points)

Hello,

The script is correct and does not require any modifications. Most probably, the issue occurs because you execute it for a lot of users in a short period of time (e.g. in a scheduled task). The only way to avoid the issue is to process all users in a single session established by a single script executed once.

0

Thanks for your response. Is there a reason, that you know of, that it used to work fine, as is, using the previous version of PS Session but has issues with this version?

0

Hello,

The only reason we can see is that you just did not hit the limit previously. As per our check, it was present long ago and the behaviour was the same. However, we are also aware of some changes in Microsoft 365 tenants that were performed recently. The behaviour you are facing might be related to that somehow. You can try checking details with Microsoft Support.

Related questions

0 votes
1 answer

How do I setup Adaxes for Exchange Online Hybrid mode? When I look at one of the users that has been migrated to Exchange Online I get the message of The operation couldn't be performed because object <user> couldn't be found on domain controller.

asked Dec 5, 2019 by Lucas.Miller (20 points)
0 votes
0 answers

Is there a way to run this report against Exchange Online instead of a local Exchange server?

asked Jul 13, 2022 by RayBilyk (230 points)
0 votes
1 answer

Hi All, I'm trying to use the powershell script provided here: https://www.adaxes.com/script-repository/move-mailbox-tofrom-microsoft-365-s579.htm Unfortuntately when executing ... credentials but I do not know why this error is happening. Thanks in advance

asked Aug 1, 2023 by curtisa (210 points)
0 votes
1 answer

Hi Team! I'm currently looking for a solution to create an exchange mailbox on-premise, sync it to Office 365 and assign the license in one business rule. I didn't ... solution from our side? Please let me know how to configure this. Best Regards Marco Jandl

asked Apr 6, 2022 by marco_jandl (60 points)
0 votes
1 answer

We have 4 om prem servers to setup Adaxes on, we currently have almost everything on one server but have crashed on several occassions when multiple scheduled jobs are ... way to achieve this configuration without having to buy double the licenses. Thanks' Jay

asked Sep 24, 2021 by willy-wally (3.2k points)
3,350 questions
3,051 answers
7,791 comments
545,074 users