Powershell script to create users in azure ad from csv file

 Here's a PowerShell script that creates user accounts in Azure Active Directory from a CSV file:


Import-Module AzureAD $users = Import-Csv -Path "C:\Users\Administrator\Documents\users.csv" Foreach ($user in $users) { New-AzureADUser -DisplayName $user.DisplayName -UserPrincipalName $user.UserPrincipalName Write-Output "User created: $($user.DisplayName)" Write-Output "----------------------------------" }


This script first imports the AzureAD module, which provides cmdlets for managing Azure Active Directory. 

Then, it uses the Import-Csv cmdlet to read the data from the CSV file into an array of PowerShell objects. 

The file should have two columns, DisplayName and UserPrincipalName, that correspond to the display name and user principal name of each user account.

The Foreach loop iterates through each object in the array, and calls the New-AzureADUser cmdlet to create a new user account 

With the specified display name and user principal name. Finally, it outputs a message indicating that each user was created.


Note: To run this script, you'll need to have the Azure Active Directory module installed and be signed in to your Azure account using the Connect-AzureAD cmdlet.

No comments:

Post a Comment