← script library

Automate User Onboarding in Microsoft Entra ID with PowerShell

Microsoft 365 & Entra IDDecember 24, 2024

In this post, we will explore a PowerShell script designed to facilitate the user onboarding process in Microsoft Entra ID (formerly Azure Active Directory). Automating user onboarding enhances operational efficiency and ensures new employees have immediate access to necessary resources. This script creates a new user, assigns roles, and provides essential information, simplifying the onboarding workflow for administrators. Here is the PowerShell script for automating user onboarding in Microsoft Entra ID:

powershell
# Connect to Microsoft Entra ID
$credential = Get-Credential
Connect-AzureAD -Credential $credential
# Define user details
$userFirstName = "Jane"
$userLastName = "Smith"
$userEmail = "[email protected]"
$jobTitle = "Software Engineer"
$department = "Development"
$passwordPolicies = "DisablePasswordExpiration"
# Create new user
New-AzureADUser -DisplayName "$userFirstName $userLastName" `
                 -GivenName $userFirstName `
                 -Surname $userLastName `
                 -UserPrincipalName $userEmail `
                 -AccountEnabled $true `
                 -MailNickName "janesmith" `
                 -PasswordProfile (New-Object Microsoft.Open.AzureAD.Model.PasswordProfile -Property @{ Password = "P@ssw0rd!" ; ForceChangePasswordNextLogin = $true }) `
                 -JobTitle $jobTitle `
                 -Department $department
Write-Host "User $userFirstName $userLastName has been onboarded successfully with email $userEmail."

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.