How to remove Accepted Senders from O365 Group in PowerShell

Grzegorz Gutowski 20 Reputation points
2024-12-19T15:54:33.0666667+00:00

Hi,

I'm using PowerShell to edit O365 (Unified Groups).

I'm able to create, and edit (add/remove) members of groups.

I'm also able to add accepted senders to a group.

I failed to remove accepted senders from a group.

I tried using Remove-MgGroupAcceptedSenderByRef or Remove-MgGroupAcceptedSenderDirectoryObjectByRef to no avail.

Function Get-MgGroupAcceptedSender returns:

Id                                                                        DeletedDateTime
--                                                                        ---------------
ba497be7-be1e-4c9a-a375-xxxxxxxxxxxx@eb0e26eb-bfbe-47d2-9e90-zzzzzzzzzzzz 
d0a75484-fa90-4f2d-87a8-yyyyyyyyyyyy@eb0e26eb-bfbe-47d2-9e90-zzzzzzzzzzzz 

Trying to call

Remove-MgGroupAcceptedSenderByRef -GroupId ... -DirecotryObjectId ba497be7-be1e-4c9a-a375-xxxxxxxxxxxx@eb0e26eb-bfbe-47d2-9e90-zzzzzzzzzzzz 

or

Remove-MgGroupAcceptedSenderByRef -GroupId ... -DirecotryObjectId ba497be7-be1e-4c9a-a375-xxxxxxxxxxxx

gives

Remove-MgGroupAcceptedSenderDirectoryObjectByRef_Delete: An internal server error occurred. The operation failed.

Status: 500 (InternalServerError)
ErrorCode: ErrorInternalServerError
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,750 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,725 questions
0 comments No comments
{count} votes

Accepted answer
  1. Vasil Michev 111.6K Reputation points MVP
    2024-12-19T16:47:54.7466667+00:00

    I'd recommend using ExO PowerShell for any Exchange-related properties, the Graph implementation is flaky at best. And the Graph SDK for PowerShell adds a layer of autogenerated crap on top of that, it ain't pretty.

    If for some reason you must use the Graph SDK for PowerShell, this should work:

    Invoke-MgGraphRequest -Uri 'https://graph.microsoft.com/v1.0/groups/efc8f64f-a605-4f39-85ca-d78350b8765d/acceptedSenders/$ref?$id=https://graph.microsoft.com/v1.0/users/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' -Method DELETE
    

    Where you must provide the id of the object to remove. Do note the use of single quotes.

    If the object you with to remove from the accepted senders list is not a user, replace the corresponding reference:

    Invoke-MgGraphRequest -Uri 'https://graph.microsoft.com/v1.0/groups/efc8f64f-a605-4f39-85ca-d78350b8765d/acceptedSenders/$ref?$id=https://graph.microsoft.com/v1.0/groups/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' -Method DELETE
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.