Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Adding users to AD - SetInfo error

$
0
0

Hi,

I'm trying to import a load of users using the script below.  I've checked it against other examples and all looks fine but it keeps throwing up the following

Exception calling "Invoke" with "2" argument(s): "There is no such object on the server.
"
At C:\Scripts\import.ps1:57 char:1
+ $objUser.Invoke("SetPassword", "password") ;
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocat
    + FullyQualifiedErrorId : DotNetMethodTargetInvocation

Exception calling "SetInfo" with "0" argument(s): "The attribute syntax specified to the directory service is invalid.
"
At C:\Scripts\import.ps1:58 char:1
+ $objUser.SetInfo()
+ ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocat
    + FullyQualifiedErrorId : CatchFromBaseAdapterMethodInvokeTI

I'd be very grateful if anyone could look this over and see if there's anything obvious that I've missed.

$objOU=[ADSI]“LDAP://OU=xx,DC=local,DC=xxx,DC=xxx”;
$dataSource=import-csv “import1.csv”;
foreach($dataRecord in $datasource)
{

$cn=$dataRecord.displayName
$sAMAccountName=$dataRecord.sAMAccountName
$givenName=$dataRecord.FirstName
$sn=$dataRecord.LastName
$sAMAccountName=$sAMAccountName.ToLower()
$displayName=$dataRecord.displayName
$userPrincipalName=$sAMAccountName + “@xxx.xxx”
$physicalDeliveryOfficeName=$dataRecord.office
$c=$dataRecord.ccode
$co=$dataRecord.country
$company=$dataRecord.company
$department=$dataRecord.department
$description=$dataRecord.title
$extensionAttribute2=$dataRecord.poboxtown
$extensionAttribute3=$dataRecord.poboxpostcode
$facsimileTelephoneNumber=$dataRecord.fax
$l=$dataRecord.office
$mobile=$dataRecord.mobile
$postalcode=$dataRecord.postalcode
$postOfficeBox=$dataRecord.postOfficeBox
$streetAddress=$dataRecord.streetAddress
$telephoneNumber=$dataRecord.telephoneNumber
$objUser=$objOU.Create(“user”, ”CN=”+$cn)

$objUser.Put(“sAMAccountName”,$sAMAccountName)
$objUser.Put(“userPrincipalName”,$userPrincipalName)
$objUser.Put(“displayName”,$displayName)
$objUser.Put(“givenName”,$givenName)
$objUser.Put(“sn”,$sn)
$objUser.Put(“physicalDeliveryOfficeName”,$physicalDeliveryOfficeName)
$objUser.Put(“c”,$c)
$objUser.Put(“co”,$co)
$objUser.Put(“company”,$company)
$objUser.Put(“department”,$department)
$objUser.Put(“description”,$description)
$objUser.Put(“title”,$description)
$objUser.Put(“extensionAttribute2”,$extensionAttribute2)
$objUser.Put(“extensionAttribute3”,$extensionAttribute3)
$objUser.Put(“facsimileTelephoneNumber”,$facsimileTelephoneNumber)
$objUser.Put(“l”,$l)
$objUser.Put(“mobile”,$mobile)
$objUser.Put(“postalcode”,$postalcode)
$objUser.Put(“postOfficeBox”,$postOfficeBox)
$objUser.Put(“streetAddress”,$streetAddress)
$objUser.Put(“telephoneNumber”,$telephoneNumber)

$objUser.userAccountControl = 512
$objUser.Invoke("SetPassword", “password”) ;
$objUser.SetInfo()
}

Thanks in advance


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>