Adding / Removing Users to Mailing Lists via Powershell

by on
1 minute read

This is a quick post for adding and removing users to mailing lists via Powershell.

1. Open a powershell window. Open start menu and type "powershell". Roght click on it and click "Run as Administrator"

2. Set Office365 login credential, in dialogue box use full email address ex:

$UserCredential = Get-Credential

3. Connect to Office365

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $UserCredential -Authentication Basic -AllowRedirection

4. Import powershell session

Import-PSSession $Session

5. Add or move users to group. Users must be specified using full email address. ex. Note: It is possible to use "for loop" if adding a bunch of users.

Add User

Add-DistributionGroupMember -Identity "mailing-list" -Member ""

Remove User

Remove-DistributionGroupMember -Identity "mailing-list" -Member ""

6. Be sure to disconnect the remote PowerShell session when you're finished. Failing to disconnect session may result in using up all available connections and will have to wait for them to expire.

Remove-PSSession $Session


comments powered by Disqus