Created
July 15, 2020 21:24
-
-
Save ppartarr/35df464ada813285ac99c6242986da91 to your computer and use it in GitHub Desktop.
Create Azure AD groups and add a given user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script requires : | |
# 1. the Azure AD Powershell module: Install-Module -Name AzureADPreview | |
# 2. an authenticated user: Connect-AzureAD | |
$uid = "" | |
$numberOfGroupsToCreate = 200; | |
for($i = 0; $i -lt $numberOfGroupsToCreate; $i++) | |
{ | |
$displayName = "GroupNamePrefix" + $i | |
# create new group | |
$output = New-AzureADGroup -DisplayName $displayName -MailEnabled $false -SecurityEnabled $true -MailNickName "NotSet" | |
# get group id of new group | |
$split = -split $output | |
$oid = $split[5] | |
# add user to group | |
Add-AzureADGroupMember -ObjectId $oid -RefObjectId $uid | |
Write-Output "successfully created group: $($displayName) with user $($uid)" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment