Automate User Onboarding in Microsoft 365 with PowerShell
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:
# 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."