← script library
Streamlining User Onboarding with PowerShell in M365
Microsoft 365 & Entra IDJanuary 4, 2025
In this installment, we are focusing on a script that automates user onboarding in Microsoft 365 (M365). Proper onboarding is crucial for organizations to ensure that new team members have the access and resources they need from day one. This PowerShell script will create a new user, assign them to predefined groups, and set up essential licenses, streamlining the entire onboarding process.
powershell
# Import the Azure AD module
Import-Module AzureAD
# Connect to Azure AD
$credential = Get-Credential
Connect-AzureAD -Credential $credential
# Define user properties
$DisplayName = "John Doe"
$userPrincipalName = "[email protected]"
$password = "P@ssw0rd!"
# Create new user
New-AzureADUser -DisplayName $DisplayName -UserPrincipalName $userPrincipalName -AccountEnabled $true -MailNickName "johndoe" -PasswordProfile @{ForceChangePasswordNextLogin=$true; Password=$password}
# License SKU
$LicenseSKU = "yourtenant:ENTERPRISEPACK" # Example for Microsoft 365 E3
# Assign license to the new user
Set-AzureADUserLicense -ObjectId $userPrincipalName -AddLicenses $LicenseSKU
# Group Object ID for the group you want to add the user to
$groupId = "Your-Group-Object-ID"
# Add user to group
Add-AzureADGroupMember -ObjectId $groupId -RefObjectId (Get-AzureADUser -ObjectId $userPrincipalName).ObjectId
# Confirm user creation and group membership
Get-AzureADUser -ObjectId $userPrincipalName
Get-AzureADGroupMember -ObjectId $groupIdRun 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.