Forum Discussion
Need assistance bulk creating M365 Dynamic Groups and configuring mail properties via powershell
Hello community,
I am able to bulk create M365 Groups (static membership) via the post link here - How to bulk create Microsoft 365 groups - Microsoft Community
This uses the 'New-UnifiedGroup' command and works great for static groups.
However, I am not able to create these groups to be dynamic. For M365 Dynamic group creation, I have to use the New-AzureADMSGroup command.
My issue is, the 'New-AzureADMSGroup' command doesnt allow for the same settings as 'New-UnfiedGroup'.
For example, I want to Create Dynamic M365 Groups, along with description, sending requirements, disable welcome message, etc.
Many of these features are not available with New-AzureADMSGroup, however New-UnifiedGroup doesnt allow to create a Dynamic group (only static)
Do i need to create with New-UnifiedGroup, then use New-AzureADMSGroup to convert to Dynamic and finalize settings?
Thanks in advance!
- Smith-EspinaCopper ContributorHere is the command for bulk create dynamic M365 groups
$attribute = "Department" # Change to the attribute you would like to use
$displayNamePrefix = "M365group" # Optionally set a Prefix for the group name
$displayNameSuffix = "Dynamic" # Optionally set a Suffix for the group name
Connect-AzureAD
$users = Get-AzureADUser -All $true
$uniqueList = $users | select $attribute -Unique | ? $attribute -ne $null
$uniqueList.($attribute) | ForEach-Object {
Write-Host "Creating Group for $($_)"
$cleanName = ($_) -replace '[*\\~;(%?.:@/,&+-]' -replace ' '
$displayName = $displayNamePrefix + $cleanName + $displayNameSuffix
$args = @{
DisplayName = $displayName
Description = "Dynamic Group for $($_)"
MailEnabled = $True
MailNickname = $displayName
SecurityEnabled = $true
GroupTypes = "DynamicMembership", "Unified"
MembershipRule = "(user.$($attribute) -eq ""$($_)"")"
MembershipRuleProcessingState = "On"
}
$dg = New-AzureADMSGroup @args
Write-Host "Group Created: $displayName"
}
Reference:
https://office365itpros.com/2019/06/27/creating-dynamic-office-365-group-global-administrators/
https://martinday.co/bulk-create-dynamic-security-groups/- JarromeAlvarezCopper ContributorVery well-verse and accurate.
- MarkOliverTagleCopper Contributornice and let me check