Skip to content

Instantly share code, notes, and snippets.

@ppartarr
Created July 15, 2020 21:24
Show Gist options
  • Save ppartarr/35df464ada813285ac99c6242986da91 to your computer and use it in GitHub Desktop.
Save ppartarr/35df464ada813285ac99c6242986da91 to your computer and use it in GitHub Desktop.
Create Azure AD groups and add a given user
# 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