Forum Discussion
How to add/remove allow sender of distribution group with powershell?
Hello,
Please help me about how to add/remove allow sender of distribution group using Powershell?
I did find a few answers like the one below:
set the allow list users addresses:
Set-DistributionGroup "group name" –AcceptMessagesOnlyFrom email address removed for privacy reasons,email address removed for privacy reasons
add the specific users to allow list:
Set-DistributionGroup "group name" –AcceptMessagesOnlyFrom @{add="email address removed for privacy reasons","email address removed for privacy reasons"}
remove the specific users to allow list:
Set-DistributionGroup "group name" –AcceptMessagesOnlyFrom @{remove="email address removed for privacy reasons","email address removed for privacy reasons"}
use the following command to check the allow list users:
Get-distributiongroup -identity "group name" | fl acceptmessagesonlyfrom
Reminder: we need to type "" in the command in powershell.
However, when I run the command, I get this error:
PS C:\WINDOWS\system32> Set-DistributionGroup "All Security Insurance" AcceptMessagesOnlyFrom @{add="email address removed for privacy reasons"}
Set-DistributionGroup : A positional parameter cannot be found that accepts argument 'AcceptMessagesOnlyFrom'.
At line:1 char:1
+ Set-DistributionGroup "All Security Insurance" AcceptMessagesOnlyFrom @{a ...
+ CategoryInfo : InvalidArgument: (:) [Set-DistributionGroup], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Set-DistributionGroup
I did connect to the exchange using: Connect-ExchangeOnline
(Import-Module ExchangeOnlineManagement)
Btw, I use the standard Office 365 portal - it is not on-premises Office.
I would be grateful for your help, please.
Thank you
Sebastian
sebgal to add a user as a sender to a DL , try the below
# Connect to Exchange Online
$UserCredential = Get-Credential
Connect-ExchangeOnline -UserPrincipalName $UserCredential.UserName# Replace "DistributionGroupName" with the actual name of your distribution group
$GroupName = "DistributionGroupName"
$NewSender = "email address removed for privacy reasons"# Add the new sender to the distribution group
Add-DistributionGroupMember -Identity $GroupName -Member $NewSender# Disconnect from Exchange Online
Disconnect-ExchangeOnline -Confirm:$falseTo remove as sender from DL, try the below
# Connect to Exchange Online
$UserCredential = Get-Credential
Connect-ExchangeOnline -UserPrincipalName $UserCredential.UserName# Replace "DistributionGroupName" with the actual name of your distribution group
$GroupName = "DistributionGroupName"
$SenderToRemove = "email address removed for privacy reasons"# Remove the sender from the distribution group
Remove-DistributionGroupMember -Identity $GroupName -Member $SenderToRemove -Confirm:$false# Disconnect from Exchange Online
Disconnect-ExchangeOnline -Confirm:$false- sebgalCopper Contributor
eliekarkafyMany thanks for getting back to me.
Your script functions excellently if I intend to add or remove a user to or from the Distribution List.
I've given it a go, and it's certainly proven to be very helpful - saved for future reference. 🙂
However, it's of particular importance for me to add a user (who is already a member of this Distribution List) to the group of senders permitted to email this distribution group email. Kindly refer to the screenshot below. I attempted to achieve this through the Office 365 Exchange portal, but I encountered an error: "Argument passed in is not serializable. Parameter name: value."
That's the reason I'm attempting to use PowerShell to accomplish this task instead.
sebgal you can do that using powershell
$UserCredential = Get-Credential
Connect-ExchangeOnline -UserPrincipalName <YourAdminEmail> -ShowProgress $true -UserCredential $UserCredentialAdd-DistributionGroupMember -Identity "DistributionListName" -Member "email address removed for privacy reasons", "email address removed for privacy reasons"
Disconnect-ExchangeOnline -Confirm:$false