Posted by: Preetam | October 17, 2007

Step02-UserCreation

$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}


Responses

  1. I run script but receive error: Exception calling “Put” with “2” argument(s): “Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))”

    how do I use put method


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: