Streamlined User Onboarding with PowerShell

Welcome to our new section dedicated to sharing useful PowerShell scripts that can enhance your workflow. One of the most crucial aspects of IT management is user onboarding, and this script simplifies the process for Microsoft Entra ID. With just a few commands, you can automate the creation of user accounts and assign appropriate roles, ensuring that your team members have access to the tools they need from day one.
Here is a sample PowerShell script for user onboarding:

# Import the required module
Import-Module AzureAD
# Define user details
$userEmail = "[email protected]"
$displayName = "New User"
$password = "P@ssw0rd!"
# Create the user
New-AzureADUser -DisplayName $displayName -UserPrincipalName $userEmail -MailNickName "newuser" -AccountEnabled $true -PasswordProfile @{ForceChangePasswordNextLogin=$true; Password=$password}
# Assign a role
$user = Get-AzureADUser -ObjectId $userEmail
Add-AzureADDirectoryRoleMember -ObjectId "your-role-object-id" -RefObjectId $user.ObjectId
Write-Host "User onboarding for $displayName completed successfully."