skip to Main Content
{ICT | Office 365 | Microsoft Teams | Surface} Perth, WA

Office 365 for Education – Bulk add users to groups

A couple of people have asked me recently how you can automate the process of putting users into groups. In this post I am going to show you one way to easily manage this using PowerShell.

Introduction

Within the Office 365 admin center, you can import a CSV of new users but cannot differentiate by role or group. So teachers and students are lumped together and there is no way to identify all of the Year 7 students, for example.

There are different ways to group users in Office 365: Mail Distribution Groups, Security Groups and SharePoint Groups. I am going to look at SharePoint Groups first – as this is the easiest and most useful for schools using Office 365 for learning management.

Set up PowerShell

For most Office 365 tasks you will use the Windows Azure AD Module – see here for details: http://aka.ms/aadposh. However as I am only working with SharePoint groups I will use the SharePoint Online Management Shell – installation instructions here. (PowerShell is already installed if you are using Windows 8 or Windows Server 2012 – you’ll only need the SharePoint Online Management Shell.)

Get the user data you need

You will need two CSV files – you should be able to export this data from your student management system. One with a list of all the groups you want to create and a second with a list of all users and what groups they belong to. For example your CSV files might look like the following.

groups.csv:

Group
Art 8
English 8
Home Economics 8
Health & Physical Education 8
Homeroom 8
Indonesian 8
Mathematics 8
Society & Environment 8
Science 8

users.csv:

LoginName Group
[email protected] Art 8
[email protected] Art 8
[email protected] Art 8
[email protected] Art 8
[email protected] Art 8
[email protected] Art 8
[email protected] Art 8
[email protected] Art 8
[email protected] Art 8
[email protected] Art 8
[email protected] English 8
[email protected] English 8
[email protected] English 8
[email protected] English 8
[email protected] English 8
[email protected] English 8
[email protected] English 8
[email protected] English 8
[email protected] English 8
[email protected]rosoft.com English 8
[email protected] Home Economics 8
[email protected] Home Economics 8
[email protected] Home Economics 8
[email protected] Home Economics 8
[email protected] Home Economics 8
[email protected] Home Economics 8
[email protected] Home Economics 8
[email protected] Home Economics 8
[email protected] Home Economics 8
[email protected] Home Economics 8

Connect to SP Online

First run SharePoint Online Management Shell and connect to O365:

Connect-SPOService -Url https://yourdomain-admin.sharepoint.com -credential [email protected]

Now upload your groups CSV file and make the required groups:

$csv = Import-Csv C:yourpath...groups.csv
foreach ($line in $csv) {
New-SPOSiteGroup -Site https://yourdomain.sharepoint.com -Group $line.Group -PermissionLevels "Edit"
}

Then upload the users CSV file and users will be placed in the groups you have just made:

$csv = Import-Csv C:yourpath...users.csv
foreach ($line in $csv) {
Add-SPOUser -Site https://yourdomain.sharepoint.com -LoginName $line.LoginName -Group $line.Group
}

That’s it. All your users are in the appropriate groups and you can add these groups to SharePoint sites, lists and libraries.

Have a look here for all the PowerShell cmdlets available for SharePoint Online and further information on the parameters for the ones I’ve used.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top
×Close search
Search