← script library
Streamline User Onboarding with PowerShell for Microsoft 365
Microsoft 365 & Entra IDJanuary 4, 2025
Managing user accounts and streamlining onboarding processes can be a daunting task, especially in a large organization. With PowerShell, you can automate these tasks efficiently. This script focuses on creating new users in Microsoft 365, assigning them licenses, and ensuring they are set up with the correct permissions.
powershell
# Install the MSOnline module if its not already installed
Install-Module MSOnline -Force
# Connect to Microsoft 365
Connect-MsolService
# Create a new user
$UserName = "[email protected]"
$Password = "P@ssw0rd" # Use a secure password
$FirstName = "New"
$LastName = "User"
$License = "yourtenant:ENTERPRISEPACK" # Replace with your SKU ID
New-MsolUser -UserPrincipalName $UserName -DisplayName "$FirstName $LastName" -FirstName $FirstName -LastName $LastName -Password $Password -ForceChangePassword $true
# Assign a license to the new user
Set-MsolUserLicense -UserPrincipalName $UserName -AddLicenses $License
# Verify the new user
Get-MsolUser -UserPrincipalName $UserName | Select DisplayName, UserPrincipalName, isLicensedRun 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.