Wednesday, 6 December 2017

Add Bulk Users to Office 365 Group with PowerShell

As you know Microsoft is targeting Office 365 Group as base service for many of cloud services like Planner, Teams and etc. So now a days every admins getting frequent request to add new on-board users to Office 365 group, we can easily achieve this task with Exchange Online powershell cmdlet Add-UnifiedGroupLinks.

Before proceed run the below commands to connect Exchange Online Powershell session.
$365Logon = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $365Logon -Authentication Basic -AllowRedirection
Import-PSSession $Session
Run the below command to add single user into Office 365 group.
Add-UnifiedGroupLinks –Identity "O365Group" –LinkType Members  –Links username@domain.com
We have to set the parameter LinkType as Members to add user as member and other valid values are Owners and Subscribers.

The parameter Links accept multiple values, we need to provide users as comma (",") separated values to add multiple members (ex: user1@domain.com,user2@domain.com....). If the user names contain spaces or otherwise require quotation marks (ex: "username 1","username 2",...).

Add multiple members to O365 group:
Add-UnifiedGroupLinks –Identity "O365Group" –LinkType Members  –Links "user1@domain.com","user2@domain.com"

Add Bulk Users to Office 365 Group from CSV

For bulk import process the CSV file is the best choice of all time, you can use the below powershell commands to add bulk members to an office 365 group by importing user identities from csv file. Consider the csv file members.csv that includes the column header member which holds the user identity values in each row of the csv file.
Import-CSV "C:\members.csv" | ForEach-Object {
Add-UnifiedGroupLinks –Identity "O365Group" –LinkType Members  –Links $_.member
}

Find and list members of unified group:

Once we added user as member in O365 group, we can use Get-UnifiedGroupLinks cmdlet to get members. The below command lists all members of given group.
Get-UnifiedGroupLinks –Identity "O365Group" –LinkType Members -ResultSize Unlimited

Advertisements
Advertisements

No comments:

Post a Comment