Add User To Azure AD Group PowerShell

This Azure article will discuss the quick steps to create Azure AD Group PowerShell and add users to Azure AD Group PowerShell

Create Azure AD group PowerShell

Let’s see how we can create a group in Azure Active Directory using PowerShell.

Connect to the Azure Account PowerShell

You must connect your PowerShell session first. Run the below command and enter your username and password.

PS C:\windows\system32> Connect-AzureAD
add users to azure ad group powershell

You can see above the session connected Successfully

Retrieve the existing groups PowerShell

You can use Get-AzureADGroups to get the list of groups in your AD using the below command.

The syntax is

Get-AzureADGroup [-All <Boolean>] [-Top <Int32>] [-Filter <String>] [<CommonParameters>]

or

Get-AzureADGroup [-SearchString <String>] [-All <Boolean>] [<CommonParameters>]

or

Get-AzureADGroup -ObjectId <String> [-All <Boolean>] [<CommonParameters>]
PS C:\windows\system32> get-azureadgroup
add members to azure ad group powershell

For specific groups, You can use the -objectID parameter to retrieve

PS C:\Windows\system32> get-azureadgroup -ObjectId 219b773f-bc3b-4aef-b320-024a2eec0b5b

Output will be

ObjectId                             DisplayName  Description                   
--------                             -----------  -----------                   
219b773f-bc3b-4aef-b320-024a2eec0b5b TSInfo Users This group is for TSInfo Users
add-azureadgroupmember

ObjectId 219b773f-bc3b-4aef-b320-024a2eec0b5b is the objectID for a specific group. In my case, it is TSInfo Users group.

Create Azure AD Groups PowerShell

You can create a group in your AD using the New-AzureADGroup command.

The syntax is

New-AzureADGroup [-InformationAction <ActionPreference>] [-InformationVariable <String>] [-Description <String>] -DisplayName <String> -MailEnabled <Boolean> -MailNickName <String> -SecurityEnabled <Boolean> [<CommonParameters>]

Parameters:

  • -Description: We can use this parameter to set the description of the AD group.
  • -DisplayName: We can set the display name for the group.
  • -InformationVariable: It sets the information variable
  • -MailEnabled: It shows whether mail is enabled or not
  • -MailNickName: It sets the mail nickname
  • -SecurityEnabled: It shows if the group is security-enabled or not.

For example:

PS C:\Windows\system32> New-AzureADGroup -Description "TsInfoGroupNew group is for TsInfo" -DisplayName "TsInfoGroupNew" -MailEnabled $false -SecurityEnabled $true -MailNickName "TsInfoGroupNew"

The output will be

ObjectId                             DisplayName    Description                       
--------                             -----------    -----------                       
23359f6d-850e-47e3-96b3-6ccae2ecb7bd TsInfoGroupNew TsInfoGroupNew group is for TsInfo

You can see below the group was created successfully.

add member to azure ad group powershell

Add users to Azure AD group PowerShell

Now our group TsInfoGroupNew has been created, we can add members to the group

We can use Add-AzureADGroupMember command to add the member to the group.

The syntax is

Add-AzureADGroupMember -ObjectId <String> -RefObjectId <String>[-InformationAction <ActionPreference>]
   [-InformationVariable <String>] [<CommonParameters>]

Parameter:

  • -ObjectId: Sets the ID of a group in Azure Active Directory.
  • -RefObjectId: Sets the ID of the Active Directory group member
PS C:\Windows\system32> Add-AzureADGroupMember -ObjectId 23359f6d-850e-47e3-96b3-6ccae2ecb7bd -RefObjectId e09bfcd-36e9-47c2-a98c-cf19412540e6
how to add user to azure ad group powershell

Here, ObjectId parameter is the ObjectID of the group, and the RefObjectId is the ObjectID of the user we want to add as a member.

FAQs

How to create and add members to Azure Active Directory Group using Azure Portal

Now, we will see how to create a group in Azure AD (Azure Active Directory) from the Azure portal.

1. Login to Azure Portal. Then click on Groups from the home page.