There will come a time when you have to create numerous user profiles in an Active Directory. Your organization has all data stored in a .csv file and you want to import it to the AD; instead of manually typing each data, this script can help you create the data in your on-premises AD, at once
Syntax
#Enter a path to your import CSV file
$ADUsers = Import-csv C:\IT\user.csv
foreach ($User in $ADUsers)
{
$Username = $User.username
$Password = $User.password
$Firstname = $User.firstname
$Lastname = $User.lastname
$email = $User.email
$OU = $User.ou
#Check if the user account already exists in AD
if (Get-ADUser -F {SamAccountName -eq $Username})
{
#If user does exist, output a warning message
Write-Warning “A user account $Username has already exist in Active Directory.”
}
else
Purpose: | This script can be easily modified as per the parameters you have defined |
Modification: | - |
Type: | PowerShell Script (ps1) |
Compatibility: | Windows |
Tags: | |
Reference link: |