Import active directory module for running AD cmdlets
Import-Module ActiveDirectory
#Store the data from ADUsers.csv in the $ADUsers variable
$ADUsers = Import-csv C:\temp\email.csv
#Loop through each row containing user details in the CSV file
foreach ($User in $ADUsers)
{
#Read user data from each field in each row and assign the data to a variable as below
$Username = $User.UserName
$Password = $User.Password
$Firstname = $User.FirstName
$Lastname = $User.LastName
$OU = $User.OU
$Fax = $User.Fax
$city = $User.city
$state = $User.state
$title = $User.title
$Department = $User.Department
$Company = $User.Company
$email = $user.email
$Description = $user.Description
#Check to see if the user already exists in AD
if (Get-ADUser -F {SamAccountName -eq $Username})
{
#If user does exist, give a warning
Write-Warning "A user account with username $Username already exist in Active Directory."
}
else
{
#User does not exist then proceed to create the new user account
#Account will be created in the OU provided by the $OU variable read from the CSV file
New-ADUser `
-SamAccountName $Username `
-UserPrincipalName "$Username@prajapati.com" `
-Name "$Firstname $Lastname" `
-GivenName $Firstname `
-Surname $Lastname `
-Enabled $True `
-email $email `
-Description $Description `
-DisplayName "$Firstname $Lastname" `
-Path $OU `
-Fax $Fax `
-City $City `
-State $State `
-title $title `
-Department $Department `
-Company $Company `
-AccountPassword (convertto-securestring $Password -AsPlainText -Force) -ChangePasswordAtLogon $false `
}
}
In questa pagina del sito puoi guardare il video online How to Create Bulk Active Directory Users Using PowerShell + CSV della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Vinod Prajapati 05 dicembre 2025, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 17 volte e gli è piaciuto 2 spettatori. Buona visione!