Add user as a member using AzureAD or Graph PowerShell

Rohit 0 Reputation points
2023-06-26T06:37:57.7333333+00:00

I have created an Azure App and trying PowerShell script to add new user as a team member in security group.

Relevant access are already provided to Azure App. Please share script or commands to add new user as a member in respective group - AzureAD and Graph PowerShell.

Intent is to add new user as a member in group.

User's image

User's image

Windows for business Windows Server User experience PowerShell
Microsoft Security Microsoft Graph
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. acotrez 0 Reputation points
    2023-06-26T10:36:24.3233333+00:00

    Hello,

    You may want to avoid AzureAD module which will no longer get support. more info on the link below.

    https://learn.microsoft.com/en-us/powershell/azure/active-directory/overview?view=azureadps-2.0

    You can use the graph module to create users and add them to groups.

    
    
    $PasswordProfile = @{
    
      Password = 'xWwvJ]6NMw+bWH-d'
    
      }
    
    $group = Get-MgGroup - Filter "DisplayName eq 'mygroupname'"
    
    $user = New-MgUser -DisplayName 'Rene Magi' -PasswordProfile $PasswordProfile -AccountEnabled -MailNickName 'ReneMagi' -UserPrincipalName '******@contoso.com'
    
    New-MgGroupMember -GroupId $group.id -DirectoryObjectId $user.id
    

    Here is a quick n' dirty patchwork from MS exemples. You can find them here, here and here :

    hope it helps


  2. Mehtab Siddique (MINDTREE LIMITED) 971 Reputation points
    2023-06-27T09:39:23.33+00:00

    Hi @Rohit,

    To add new users to the security groups here are the permissions required and also this is not supported for the delegated permissions only for Application permissions.

    User's image

    Query:

    Import-Module Microsoft.Graph.Groups
    
    $params = @{
    	"@odata.id" = "https://graph.microsoft.com/v1.0/directoryObjects/{id}"
    }
    
    New-MgGroupMemberByRef -GroupId $groupId -BodyParameter $params
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.