Hello,
So I'm attempting to do a bulk creation of users into Active Directory (Server 2008) using Powershell. I have a script but every time it runs it throws a exception error. I have tried to go through and find what is wrong, but I am having little luck. Any help would be greatly appreciated!
Script:
$objOU=[ADSI]“LDAP://OU=Users,DC=notmyrealdchere,DC=com”
$list = Import-Csv "userImport.csv"
foreach ($dataRecord in $list)
{
$cn=$dataRecord.FirstName + ” ” + $dataRecord.LastName
$sAMAccountName=$dataRecord.FirstName + “.” + $dataRecord.LastName
$givenName=$dataRecord.FirstName
$surName=$dataRecord.LastName
$sAMAccountName=$sAMAccountName.ToLower()
$displayName=$surName + “, ” + $givenName
$userPrincipalName=$sAMAccountName + “@itas.ca”
$objUser=$objOU.Create(“user”,”CN=”+$cn)
$objUser.Put(“sAMAccountName”,$sAMAccountName)
$objUser.Put(“userPrincipalName”,$userPrincipalName)
$objUser.Put(“displayName”,$displayName)
$objUser.Put(“givenName”,$givenName)
$objUser.Put(“surName”,$surName)
$objUser.SetInfo()
$objUser.SetPassword(“P@assw0rd”)
$objUser.psbase.InvokeSet(“AccountDisabled”,$false)
$objUser.SetInfo()
}
Error:
At line:10 char:10
+ $objUser= <<<< $objOU.Create("user","CN="+$cn)
+ CategoryInfo : NotSpecified: (:) [], ExtendedTypeSystemException
+ FullyQualifiedErrorId : CatchFromBaseGetMember
You cannot call a method on a null-valued expression.
At line:11 char:13
+ $objUser.Put <<<< ("sAMAccountName",$sAMAccountName)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
(Does this for many many lines (maybe all?))