$OUName=read-host “Please enter the OU name in which you wish to create users”
$objUser = [ADSI]“LDAP://localhost:389/dc=contoso,dc=com”
$IndiaOU=[ADSI]“LDAP://localhost:389/ou=$OUName,dc=contoso,dc=com”
if($IndiaOU.true){
$UserDetails=Import-Csv “users.csv”
foreach($UD in $UserDetails) {
$CN=$UD.CN
$SN=$UD.SN
$title=$UD.title
$description=$UD.description
$department=$UD.department
$streetAddress=$UD.streetAddress
$postalcode=$UD.postalcode
$telephoneNumber=$UD.telephoneNumber
$givenName=$UD.givenName
$company=$UD.company
$mail=$UD.mail
$homePhone=$UD.homePhone
$mobile=$UD.mobile
$userPrincipalName=$UD.userPrincipalName
$Samaccountname=$UD.Samaccountname
$Location=$UD.l
$State=$UD.ST
$Indiauser=$IndiaOU.create(“user”,”cn=$cn”)
$Indiauser.Put(“sAMAccountName”,$Samaccountname)
$Indiauser.put(“SN”,$SN)
$Indiauser.put(“Title”,$title)
$Indiauser.put(“Description”,$description)
$Indiauser.put(“department”,$department)
$Indiauser.put(“streetAddress”,$streetAddress)
$Indiauser.put(‘telephoneNumber’,$telephoneNumber)
$Indiauser.put(‘givenName’,$givenName)
$Indiauser.put(‘company’,$company)
$Indiauser.put(‘mail’,$mail)
$Indiauser.put(‘homePhone’,$homePhone)
$Indiauser.put(‘mobile’,$mobile)
$Indiauser.put(‘L’,$Location)
$Indiauser.put(‘ST’,$State)
$Indiauser.put(‘userPrincipalName’,$userPrincipalName)
$Indiauser.setinfo()
$Indiauser.psbase.Invoke(“SetPassword”,”P@ssW0Rd”)
$Indiauser.psbase.InvokeSet(‘Accountdisabled’,$false)
$Indiauser.psbase.CommitChanges()
}
}
else {Write-host “Errr OU doesn’t exist to proceed further, please create one” -foregroundcolor RED}