Home ยป Office 365 ยป Add-MsolGroupMember – Add Users to the Security Group in Office 365

Add-MsolGroupMember – Add Users to the Security Group in Office 365

The Add-MsolGroupMember cmdlet in PowerShell adds a member to an existing security group in Office 365. The new members can be either users or other security groups.

The syntax for adding a new member to the Office 365 MSOL group is below.

Add-MsolGroupMember
   -GroupObjectId <Guid>
   [-GroupMemberType <GroupMemberType>]
   [-GroupMemberObjectId <Guid>]
   [-TenantId <Guid>]
   [<CommonParameters>]

In this article, we will discuss how to use the Add-MsolGroupMember cmdlet in PowerShell to add a new user to a security group.

How to Add a User to a Security Group in Office 365

To add a user to a security group in Office 365, use the Get-MsolGroupMember cmdlet with the -GroupObjectId parameter. The -GroupObjectId parameter specifies the unique ID of the group to which we want to add a new member.

The -GroupMemberType parameter specifies the member type, in this case, โ€œuserโ€œ. The -GroupMemberObjectId parameter specifies the unique ID of the member in the group.

# Get the User
$User = Get-MsolUser -UserPrincipalName "[email protected]" 

# Get the Group object in Office 365 
$Group = Get-MsolGroup -ObjectId "008f363f-5b3a-4899-8004-a2d140426802"

# Add a new user to the security group
Add-MsolGroupMember -GroupObjectId $Group.ObjectId -GroupMemberObjectId $User.ObjectId -GroupMemberType User 

This command adds a user to a security group.

Conclusion

I hope the above article on how to use the Add-MsolGroupMember cmdlet in PowerShell to add a new member to the group is helpful to you. You can add multiple members to a group.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.

Related Links

Get-MsolGroupMember

Remove-MsolGroupMember