Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Add users to an AAD group through Powershell

Posted on 2016-11-02
4
Medium Priority
?
98 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 18

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 43

Accepted Solution

by:
Vasil Michev (MVP) earned 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
This Experts Exchange lesson shows how to use VBA to loop through rows in Excel.  In order to sort, filter, and use database features, there needs to be a value in each column for every row. When data arrives with values missing, code to copy values…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

688 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