← script library

Automate User Onboarding in Microsoft 365 with PowerShell

Microsoft 365 & Entra IDDecember 24, 2024

In this post, we will explore a PowerShell script designed to automate the user onboarding process in Microsoft 365. Streamlining user onboarding is crucial for enhancing productivity and ensuring that new employees can start working without unnecessary delays. This script allows IT administrators to create new users, assign licenses, and set the initial password all in one go, simplifying the onboarding workflow. Here is the PowerShell script for automating user onboarding:

powershell
# Connect to Microsoft 365
$credential = Get-Credential
Connect-MsolService -Credential $credential
# Define user details
$userFirstName = "John"
$userLastName = "Doe"
$userEmail = "[email protected]"
$userPassword = "P@ssw0rd!"  # Ensure to follow your password policy
$licenses = "yourtenant:STANDARDPACK"  # Modify with the actual license SKU
# Create new user
New-MsolUser -FirstName $userFirstName -LastName $userLastName -UserPrincipalName $userEmail -DisplayName "$userFirstName $userLastName" -Password $userPassword -ForceChangePassword $false
# Assign license to the new user
Set-MsolUserLicense -UserPrincipalName $userEmail -AddLicenses $licenses
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.