Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 112
  • Last Modified:

Add users to an AAD group through Powershell

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
John Davies
Asked:
John Davies
  • 2
1 Solution
 
Gaurav SinghSolution ArchitectCommented:
0
 
John DaviesAuthor Commented:
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
 
Vasil Michev (MVP)Commented:
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
 
John DaviesAuthor Commented:
Thank you, worked a treat.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now