Add Members to Office 365 Group using PowerShell

Requirement: Add members to office 365 group using PowerShell

Add user to Office 365 Group using Admin Center:
As an admin, you can add members to any Office 365 group through Microsoft 365 admin center. Here is how:
  • Login to the Microsoft 365 Admin Center site: https://admin.microsoft.com
  • Expand Groups and Click on Groups link in the left navigation. 
  • Select the Office 365 group you wish to add members
  • Click on Edit link next to Members column in the details pane.
    add user to office 365 group using powershell
  • On the Group page, Click on Add Members button >> Search and select users you wish to add to the group. You can find and add multiple users in a single stretch.
    how to add users to office 365 group powershell
  • Click on "Save" once you are done! You'll see "Group membership was updated and will take effect immediately." message.

How to Add Users to Office 365 Group using PowerShell?
Let's add "John@TheCrescentTech.com" to "Accounts@TheCrescentTech.com" Office 365 group using PowerShell.
#Get Credentials to connect
$Credential = Get-Credential
 
#Create the session
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ `
           -Credential $Credential -Authentication Basic -AllowRedirection
 
#Import the session
Import-PSSession $Session -DisableNameChecking

#PowerShell to add user to office 365 group
Add-UnifiedGroupLinks –Identity "Accounts@TheCrescentTech.com" –LinkType "Members" –Links "john@TheCrescentTech.com"

#Remove the session
Remove-PSSession $Session 

Bulk Add Members to Office 365 Group using PowerShell
Likewise, you can add multiple users comma separated. E.g.
Add-UnifiedGroupLinks –Identity "Accounts@TheCrescentTech.com" –LinkType "Members" –Links "john@TheCrescentTech.com","peter@TheCrescentTech.com"
 
PowerShell to Add Users to Office 365 Group from CSV
Here is how to bulk add members to Office 365 group from a CSV file using PowerShell:
PowerShell to Add Users to Office 365 Group from CSV
Import Office 365 Groups from CSV File:
#Get Credentials to connect
$Credential = Get-Credential
 
#Create the session
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ `
           -Credential $Credential -Authentication Basic -AllowRedirection
 
#Import the session
Import-PSSession $Session -DisableNameChecking

#PowerShell to Import Members to office 365 group from CSV
Import-CSV "C:\Temp\GroupMembers.csv" | ForEach-Object {
    Add-UnifiedGroupLinks –Identity $_.GroupID –LinkType Members –Links $_.Member
    Write-host -f Green "Added Member '$($_.Member)' to Office 365 Group '$($_.GroupID)'"
}

#Remove the session
Remove-PSSession $Session
Add Members to Office 365 Group using PowerShell Add Members to Office 365 Group using PowerShell Reviewed by Salaudeen Rajack on May 26, 2018 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.