Home > Net >  How to assign user to all possible groups in Azure Active Directory?
How to assign user to all possible groups in Azure Active Directory?

Time:03-22

I want to add to the user all possible group memberships in the Azure Active Directory, but there are so many groups so I dont want to do it manually, is there any script or button to do this quickly?

CodePudding user response:

• Yes, you can surely do that through a powershell script wherein you would need to export the details of all the groups present in Azure AD to a CSV file or to the console. And then call every group to add the said user whose object ID is specified in the powershell command to every group. Please find the below prepared and tested powershell script for the specified user in all the groups present in Azure AD.

Powershell script: -

  Connect-AzureAD
   $groups=Get-AzureADGroup | Select-Object ObjectID
    foreach($group in $groups) {Add-AzureADGroupMember -ObjectId $group.ObjectId -RefObjectId "f08cdf62-6d20-4b65-bdd8-33f84c61802f"} ’

• Results: -

User's object ID Group membership Groups present

Please find below Microsoft documentation for your reference: -

https://docs.microsoft.com/en-us/azure/active-directory/enterprise-users/groups-settings-v2-cmdlets#add-members

CodePudding user response:

try this in powershell install azure AD module

   PS C:\Windows\system32> install-module azuread
   PS C:\Windows\system32> import-module azuread

you can verify it by :

PS C:\Windows\system32> get-module azuread

Now connect your powershell to the directory

PS C:\Windows\system32> Connect-AzureAD

it will prompts you for the credentials you want to use to access your directory and returns a confirmation to show the session was connected successfully to your directory:

     Account                       Environment Tenant ID
    -------                       ----------- ---------
    [email protected]      AzureCloud  23b5ff1e-3402-800c-823c-3f…

To retrieve existing groups from your directory, use the Get-AzureADGroups cmdlet

$groups= get-azureadgroup 
foreach ($group in $groups)
{

Add-AzureADGroupMember -ObjectId $group.ObjectId -RefObjectId <user reference id>
}

replace the user reference id, you can use Get-AzureADUser to get that

  • Related