Jump to content
EduGeek EdSec 2026 is Go! 27th Oct in Derby! Join us for a day of EdTech security focused talks, networking, and an evening social ×
  • entries
    60
  • comments
    63
  • views
    837

Add members to an Office 365 distribution group with powershell.


There's 2 ways to connect to office365 through powershell.

 

MSOL

Exchange online.

 

You can add members to a security group using MSOL but you have to use EOL for distribution groups or mail-enabled security groups.

 

At this juncture I only know how to get user data using msol.

 

(we use -like @ domain because pupils have a different subdomain)

 

 

#connect MSOL
connect-msolservice

get-msoluser -all | where-object {$_.userprincipalname -like  "domain"} | export-csv -path "d:\staffemails.csv" 

#connect EOL
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri [url]https://outlook.office365.com/powershell-liveid/[/url] -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session -DisableNameChecking

import-csv "d:\staffemails.csv" | foreach {add-distributiongroupmember -identity "groupname" -member $_.userprincipalname}

Edited by browolf

0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...