Solved

Add users to an AAD group through Powershell

Posted on 2016-11-02
4
45 Views
Last Modified: 2016-11-02
Need a quick answer so any help would be appreciated.

Does anyone have a powershell script to add ALL USERS and INDIVIDUAL USERS to AAD groups. We have a group in AZURE AD that I need to populate with several hundred users.

This is an Pure Cloud based solution of Office 365

Ta
0
Comment
Question by:John Davies
  • 2
4 Comments
 
LVL 17

Expert Comment

by:Gaurav Singh
ID: 41869787
0
 

Author Comment

by:John Davies
ID: 41869893
Hi Gaurav, this has no on prem, it is purely cloud am trying to add users to an AZURE AD group, cant use the Import-Module ActiveDirectory

Import-Module : The specified module 'activedirectory' was not loaded because no valid module file was found in any module directory.
0
 
LVL 40

Accepted Solution

by:
Vasil Michev (MVP) earned 500 total points
ID: 41869920
You can use the WAAD PowerShell module and the Add-MsolGroupMember cmdlet. For example, to add all users to a specific group:

$group = Get-MsolGroup | ? {$_.DisplayName -eq "test"} | select -ExpandProperty ObjectId

Get-MsolUser -All | % { Add-MsolGroupMember -GroupObjectId $group.Guid -GroupMemberObjectId $_.ObjectId.Guid }

Open in new window


Or, if you are using Exchange Online as well, take advantage of the Add-DistributionGroupMember cmdlet, which is far more convenient:

Get-User | % { Add-DistributionGroupMember DG -Member $_.UserPrincipalName -WhatIf }

Open in new window


Here are links to the modules:

https://technet.microsoft.com/en-us/library/dn975125.aspx
https://technet.microsoft.com/en-us/library/jj984289(v=exchg.160).aspx
0
 

Author Closing Comment

by:John Davies
ID: 41870587
Thank you, worked a treat.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Scam emails are a huge burden for many businesses. Spotting one is not always easy. Follow our tips to identify if an email you receive is a scam.
Read this checklist to learn more about the 15 things you should never include in an email signature.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
how to add IIS SMTP to handle application/Scanner relays into office 365.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question