Azure Active Directory (AD) empowers organizations to manage user identities and access to resources efficiently. When dealing with a large number of security groups, automating their creation becomes essential.
In this guide, we'll demonstrate how to use PowerShell along with a CSV file to automate the bulk creation of Azure AD Security Groups.
Prerequisites
- Microsoft Graph PowerShell SDK installed (
Install-Module Microsoft.Graph -Scope CurrentUser). The legacy AzureAD PowerShell module was retired in mid-2025, soConnect-AzureADandNew-AzureADGroupno longer work -- the script below uses the Graph SDK equivalents. - Appropriate permissions to create groups in Azure AD (the
Group.ReadWrite.AllGraph scope). - A CSV file containing the necessary attributes for the security groups (DisplayName, Description, MailNickName).
Step-by-Step Guide to Creating Azure AD Security Group in Bulk Using PowerShell and CSV
Step 1: Prepare Your CSV File
Create a CSV file with columns for the attributes of the security groups you wish to create (e.g., DisplayName, Description, MailNickName). Ensure the data is correctly formatted and that each row represents a single security group.
DisplayName,Description,MailNickName
Group1,Security Group 1,group1
Group2,Security Group 2,group2
...
Step 2: PowerShell Scripting
Use PowerShell scripting to import the CSV file and create Azure AD Security Groups based on the provided data. Here's a PowerShell script using the Microsoft Graph PowerShell SDK to create Azure AD groups in bulk:
# Connect to Microsoft Graph
Connect-MgGraph -Scopes "Group.ReadWrite.All"
# Path to your CSV file
$csvPath = "C:\path\to\your\file.csv"
# Read CSV file
$groups = Import-Csv -Path $csvPath
foreach ($group in $groups) {
$displayName = $group.DisplayName
$description = $group.Description
$mailNickname = $group.MailNickName
# Create the security group
New-MgGroup -DisplayName $displayName -Description $description -MailNickname $mailNickname -SecurityEnabled -MailEnabled:$false
}
Adjust the CSV path according to the location of your CSV file. If you're still on the retired AzureAD module, the equivalent old cmdlet was New-AzureADGroup -DisplayName $displayName -Description $description -MailNickname $mailNickname -SecurityEnabled $true -MailEnabled $false -- swap it for New-MgGroup above.
Step 3: Executing the Script
Save the script with a .ps1 extension and execute it in PowerShell. Ensure you have the necessary permissions to create groups in Azure AD.
Step 4: Validation and Testing
Before applying the script in a production environment, test it in a non-production environment to ensure it works as expected. Check for any errors or mismatches in the data.
Automating the creation of Azure AD Security Groups using a CSV file and PowerShell streamlines administrative tasks, especially in scenarios involving the management of numerous groups. This approach saves time, minimizes errors, and enhances the efficiency of managing Azure AD resources.
Related
- New to the Graph PowerShell SDK? See our guide on connecting to Microsoft Graph using PowerShell for module installation and authentication scopes.
- Once your groups exist, you can add descriptions to multiple groups in bulk the same CSV-driven way.
- Not sure whether you need a security group, Microsoft 365 group, or distribution list? See our overview of types of groups in Microsoft 365.
- For membership that updates itself instead of a static CSV import, see dynamic membership rules using PowerShell.