Problem with AD script
hi guys,
i managed script can take details input file(csv) , create users in active directory.
but doesnot create logon id( samaccountname...
appreciate if experts can me solve issue. script using.
$users = import-csv users.csv
$users | foreach-object {
$userfirstname = $_.firstname #givenname (i.e. first name)
$userlastname = $_.lastname #sn or surname (i.e. last name)
$userloginid = $_.samaccountname #samaccountname; pre-windows 2000 login id
$userprincipalname = $_.upn #secondary login id or active directory login id
$userprincipalname = $userprincipalname + "@somedomain.com" #append domain name here
$userdisplayname = $userfirstname + " " + $userlastname #displayname & cn name
write-host "displayname: $userdisplayname"
$objdomain = new-object system.directoryservices.directoryentry
$objuser = $objdomain.create("user", "cn=" + $userdisplayname) #this creates local object update
$objuser.put("givenname",$userfirstname)
$objuser.put("sn",$userlastname)
$objuser.put("samaccountname",$userloginid)
$objuser.put("displayname",$userdisplayname)
$objuser.put("userprincipalname",$userprincipalname)
$objuser.setinfo() #this create user id on domain, disabled. required set pas
word or enable id.
$objuser.accountdisabled = $false #by default user id disabled , must enabled use.
$objuser.setpassword("default123") #set password need be
$objuser.setinfo()
}
this error get
displayname: tfnam tlnam
exception calling "put" "2" argument(s): "unspecified error (exception hresult: 0x80004005 (e_fail))"
@ line:13 char:17
+ $objuser.put <<<< ("samaccountname",$userloginid)
+ categoryinfo : notspecified: (:) [], methodinvocationexception
+ fullyqualifiederrorid : catchfrombaseadaptermethodinvoketi
thanks in advance
alex
users objects have several names. common name (the value of cn attribute) labeled "name" in aduc. value of userdisplayname in script. assigned same value optional displayname attribute, shows on "general" tab of properties in aduc (displayname missing). cannot logon common name. the common name must unique in ou or container, not uniquely identify user. there users same common name in other ou's.
the "pre-windows 2000 logon" name (the value of samaccountname attribute) shows on "account" tab in aduc. must unique in domain , users can logon (as long domain specified). finally, users can logon userprincipalname. shows on "account" tab , must unique in forest. help?
richard mueller - mvp directory services
Windows Server > Windows PowerShell
Comments
Post a Comment