← script library
Streamline User Onboarding in Microsoft 365 with PowerShell
Microsoft 365 & Entra IDDecember 24, 2024
In this post, we will share a PowerShell script designed to automate the user onboarding process in Microsoft 365. Efficient onboarding is critical for ensuring that new employees can hit the ground running with access to necessary resources. This script enables administrators to create new users, assign licenses, and set their initial passwords all in one streamlined process. Here is the PowerShell script for automating user onboarding in Microsoft 365:
powershell
# Connect to Microsoft 365
$credential = Get-Credential
Connect-MsolService -Credential $credential
# Define user details
$userFirstName = "Alex"
$userLastName = "Johnson"
$userEmail = "[email protected]"
$userPassword = "InitialP@ssw0rd" # Ensure to follow your organization's password policy
$licenseSku = "yourtenant:ENTERPRISEPACK" # Replace with your actual license SKU
# Create the new user
New-MsolUser -FirstName $userFirstName `
-LastName $userLastName `
-UserPrincipalName $userEmail `
-DisplayName "$userFirstName $userLastName" `
-Password $userPassword `
-ForceChangePassword $true
# Assign the license to the new user
Set-MsolUserLicense -UserPrincipalName $userEmail -AddLicenses $licenseSku
Write-Host "User $userFirstName $userLastName has been successfully onboarded 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.
More in Microsoft 365 & Entra ID
Automate M365 User License Assignment with PowerShell
2025-01-09Manage M365 Users with PowerShell
2025-01-09Automate Microsoft 365 User License Management with PowerShell
2025-01-09Streamlining M365 User Management with PowerShell
2025-01-09PowerShell Script to Retrieve M365 User License Info
2025-01-09Automate Microsoft 365 User Report Generation with PowerShell
2025-01-09Ready when you are.
Try ServerEngine free for 7 days.