Are you an IT admin or cloud engineer tired of manually creating security groups in Azure Active Directory?
Well, you’re not alone. Whether you’re managing user access, setting up role-based access control, or organizing groups for Microsoft 365 services—doing it one by one is time-consuming and prone to human error.
In this blog, I’ll walk you through a practical PowerShell script that helps you create multiple Azure AD groups in bulk. I’ll explain every line of the script in plain, human-friendly language. This guide is crafted to be easy to follow—even if you’re not a scripting expert.
Let’s dive in!
Prerequisites
Before you run the script, make sure you meet the following requirements:
– You have the necessary admin rights to create groups and assign owners in Azure AD.
– You have PowerShell installed with the AzureAD module.
– You are connected to both Exchange Online and Azure AD using PowerShell.
– A CSV file with the group names is prepared in advance (more on that below).
Step-by-Step PowerShell Script Explanation
Here’s the full script we’ll be using:
Connect-ExchangeOnline
Install-Module -Name AzureAD
Connect-AzureAD
$Names = Import-Csv "C:\Users\Desktop\ProvidedNames.csv"
foreach ($name in $Names) {
$group = New-AzureADGroup -DisplayName $name.dpname -Description "enter your description" -MailEnabled $false -SecurityEnabled $true -MailNickname $mailbox.dpname
$owner = "OwnerEmailAddress"
Add-AzureADGroupOwner -ObjectId $group.ObjectId -RefObjectId (Get-AzureADUser -ObjectId $owner).ObjectId
}
Now let’s break it down:
Connect-ExchangeOnline
This command is used to establish a remote session with Exchange Online. It’s essential if you plan to work with mail-enabled groups later.
Install-Module -Name AzureAD
This installs the AzureAD PowerShell module which allows you to manage Azure Active Directory resources.
Connect-AzureAD
This command authenticates your session to Azure AD. A login prompt will appear where you’ll enter your credentials.
$Names = Import-Csv
This line imports group names from a CSV file located on your desktop. Each row in the CSV should contain a column named ‘dpname’.
foreach loop
This loop goes through each entry in the CSV file, creating a new Azure AD group for each name found.
New-AzureADGroup
This command creates the actual group. You can customize the description and change the MailEnabled or SecurityEnabled flags as per your needs.
Add-AzureADGroupOwner
This command assigns an owner to the newly created group. The owner email should be an existing user in Azure AD.
Sample Output
Here’s what you can expect after running the script successfully:
Creating Group: IT_Admins
Owner Assigned: admin@yourdomain.com
Creating Group: HR_Team
Owner Assigned: hrmanager@yourdomain.com
… and so on for every entry in the CSV file.
No errors? Congratulations! Your groups have been created successfully.
Common Issues and Troubleshooting Tips
• Error: ‘New-AzureADGroup is not recognized’ → Make sure AzureAD module is installed and imported properly.
• Error: ‘Object reference not set’ → Check that your CSV file is correctly formatted and that the ‘dpname’ column exists.
• Authentication failures? → Make sure MFA is not blocking the session or use a service principal for automation.
Conclusion
Creating Azure AD groups in bulk using PowerShell can save you a ton of time—especially in large organizations. With the help of a well-structured script and a clear CSV file, you can automate this task and focus on more strategic work.
Hope you found this guide helpful. If you did, feel free to share it and drop your comments below. Happy scripting!