← 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, isLicensed

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.