Automate User Onboarding for Microsoft Entra ID with PowerShell
Onboarding new users can often be a lengthy and complicated process, especially in large organizations. Using PowerShell, you can streamline user provisioning in Microsoft Entra ID (formerly Azure Active Directory). This script automates the creation of users, assigns licenses, and adds them to security groups.
Follow the steps below to implement an efficient user onboarding process using PowerShell.
### Step 1: Install the Required Module
Make sure you have the AzureAD module installed. This module contains the cmdlets necessary for managing users in Microsoft Entra ID.
“`powershell
# Install the AzureAD module if it isnt already installed Install-Module AzureAD -Force
“`
### Step 2: Connect to Microsoft Entra ID
Before you can manage users, establish a connection to your Microsoft Entra ID.
“`powershell
# Connect to Microsoft Entra ID Connect-AzureAD
“`
### Step 3: Define New User Attributes
Determine the attributes for the user you intend to create, including details such as username, password, and other necessary information.
“`powershell
# Define new user attributes $UserPrincipalName = "[email protected]" $DisplayName = "New User" $FirstName = "New" $LastName = "User" $Password = "P@ssw0rd!" # Ensure this password meets password policy requirements $License = "yourtenant:ENTERPRISEPACK" # Replace with your appropriate SKU ID $GroupName = "YourSecurityGroup" # Replace with the desired security group
“`
### Step 4: Create the User
Using the defined attributes, create a new user in Microsoft Entra ID.
“`powershell
# Create the new user New-AzureADUser -UserPrincipalName $UserPrincipalName -DisplayName $DisplayName -GivenName $FirstName -Surname $LastName -AccountEnabled $true -PasswordProfile @{ ForceChangePasswordNextLogin = $true; Password = $Password }
“`
### Step 5: Assign a License and Add to Group
Now that the user is created, assign them a license and add them to the designated security group.
“`powershell
# Assign a license to the new user Set-AzureADUserLicense -ObjectId $UserPrincipalName -AssignedLicenses @{SkuId=$License} # Add the user to the specified security group $group = Get-AzureADGroup -SearchString $GroupName Add-AzureADGroupMember -ObjectId $group.ObjectId -RefObjectId (Get-AzureADUser -ObjectId $UserPrincipalName).ObjectId
“`
### Conclusion
This PowerShell script allows you to automate the user onboarding process in Microsoft Entra ID, ensuring that new users are set up quickly and accurately. Such automation can save time and reduce the potential for errors during onboarding.
To explore more powerful server management solutions, check out ServerEngine at [https://serverengine.co](https://serverengine.co). Boost your operational efficiency with our suite of automation tools!