Adding / Removing Users to Mailing Lists via Powershell
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: email@example.com
$UserCredential = Get-Credential
3. Connect to Office365
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
4. Import powershell session
5. Add or move users to group. Users must be specified using full email address. ex. firstname.lastname@example.org. Note: It is possible to use "for loop" if adding a bunch of users.
Add-DistributionGroupMember -Identity "mailing-list" -Member "email@example.com"
Remove-DistributionGroupMember -Identity "mailing-list" -Member "firstname.lastname@example.org"
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.
Let me know what you think of this article on twitter @TTLequals0 or leave a comment below!