← script library

Automate Microsoft Entra ID User Management with PowerShell

Microsoft 365 & Entra IDDecember 24, 2024

In this post, we will share a PowerShell script designed to automate user management tasks in Microsoft Entra ID (formerly Azure Active Directory). Managing user accounts efficiently is vital for maintaining security and ensuring that users have proper access to company resources. This script allows administrators to create new users, update user details, and even remove users, all with minimal effort. Here is the PowerShell script for managing users in Microsoft Entra ID:

powershell
# Connect to Microsoft Entra ID
$credential = Get-Credential
Connect-AzureAD -Credential $credential
# Define user details for creation
$userFirstName = "Emily"
$userLastName = "Davis"
$userEmail = "[email protected]"
$userPassword = "InitialP@ssw0rd"
$jobTitle = "Project Manager"
$department = "Management"
# Create a new user
New-AzureADUser -DisplayName "$userFirstName $userLastName" `
                 -GivenName $userFirstName `
                 -Surname $userLastName `
                 -UserPrincipalName $userEmail `
                 -AccountEnabled $true `
                 -MailNickName "emilydavis" `
                 -PasswordProfile (New-Object Microsoft.Open.AzureAD.Model.PasswordProfile -Property @{ Password = $userPassword; ForceChangePasswordNextLogin = $true }) `
                 -JobTitle $jobTitle `
                 -Department $department
Write-Host "User $userFirstName $userLastName has been created successfully."

Run it across your fleet

This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.

Ready when you are.

Try ServerEngine free for 7 days.