← script library

Automate User Onboarding for Microsoft Entra ID with PowerShell

Microsoft 365 & Entra IDJanuary 4, 2025

Onboarding new users can often be a lengthy and complicated process, especially in large organizations. Using PowerShell, you can streamline user provisioning in Microsoft Entra ID (formerly Azure Active Directory). This script automates the creation of users, assigns licenses, and adds them to security groups. Follow the steps below to implement an efficient user onboarding process using PowerShell.

powershell
# Install the AzureAD module if it isnt already installed
Install-Module AzureAD -Force

# Connect to Microsoft Entra ID
Connect-AzureAD

# Define new user attributes
$UserPrincipalName = "[email protected]"
$DisplayName = "New User"
$FirstName = "New"
$LastName = "User"
$Password = "P@ssw0rd!"  # Ensure this password meets password policy requirements
$License = "yourtenant:ENTERPRISEPACK"  # Replace with your appropriate SKU ID
$GroupName = "YourSecurityGroup"  # Replace with the desired security group

# Create the new user
New-AzureADUser -UserPrincipalName $UserPrincipalName -DisplayName $DisplayName -GivenName $FirstName -Surname $LastName -AccountEnabled $true -PasswordProfile @{ ForceChangePasswordNextLogin = $true; Password = $Password }

# Assign a license to the new user
Set-AzureADUserLicense -ObjectId $UserPrincipalName -AssignedLicenses @{SkuId=$License}
# Add the user to the specified security group
$group = Get-AzureADGroup -SearchString $GroupName
Add-AzureADGroupMember -ObjectId $group.ObjectId -RefObjectId (Get-AzureADUser -ObjectId $UserPrincipalName).ObjectId

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.