Hi
PLEASE HELP.
I have a tons of users to create and i want to import them using csv on powershell, but i keep getting errors.
Bulk is my script and my error:
Script
$objOU=[ADSI]"LDAP://OU=Staff,OU=StratOrg,DC=workforcegroup,DC=com"
$dataSource=import-csv "StratOrg.csv"
foreach($dataRecord in $datasource) {
$cn=$dataRecord.GivenName + " " + $dataRecord.Surname
$sAMAccountName=$dataRecord.GivenName + "." + $dataRecord.Surname
$givenName=$dataRecord.GivenName
$sn=$dataRecord.Surname
$sAMAccountName=$sAMAccountName.ToLower()
$displayName=$dataRecord.DisplayName
$userPrincipalName=$sAMAccountName + "@workforcegroup.com"
$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.SetInfo()
$objUser.SetPassword("P@ss123")
$objUser.psbase.InvokeSet("AccountDisabled",$false)
$objUser.SetInfo()
}
Error
The following exception occurred while retrieving member "create": "There is no such object on the server.
"
At line:10 char:11
+ $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:14
+ $objUser.Put <<<< ("sAMAccountName",$sAMAccountName)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:12 char:14
+ $objUser.Put <<<< ("userPrincipalName",$userPrincipalName)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:13 char:14
+ $objUser.Put <<<< ("displayName",$displayName)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:14 char:14
+ $objUser.Put <<<< ("givenName",$givenName)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:15 char:14
+ $objUser.Put <<<< ("sn",$sn)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:16 char:18
+ $objUser.SetInfo <<<< ()
+ CategoryInfo : InvalidOperation: (SetInfo:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:17 char:22
+ $objUser.SetPassword <<<< ("P@ss123")
+ CategoryInfo : InvalidOperation: (SetPassword:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:18 char:27
+ $objUser.psbase.InvokeSet <<<< ("AccountDisabled",$false)
+ CategoryInfo : InvalidOperation: (InvokeSet:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:19 char:18
+ $objUser.SetInfo <<<< ()
+ CategoryInfo : InvalidOperation: (SetInfo:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
The following exception occurred while retrieving member "create": "There is no such object on the server.
"
At line:10 char:11
+ $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:14
+ $objUser.Put <<<< ("sAMAccountName",$sAMAccountName)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:12 char:14
+ $objUser.Put <<<< ("userPrincipalName",$userPrincipalName)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:13 char:14
+ $objUser.Put <<<< ("displayName",$displayName)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:14 char:14
+ $objUser.Put <<<< ("givenName",$givenName)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:15 char:14
+ $objUser.Put <<<< ("sn",$sn)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:16 char:18
+ $objUser.SetInfo <<<< ()
+ CategoryInfo : InvalidOperation: (SetInfo:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:17 char:22
+ $objUser.SetPassword <<<< ("P@ss123")
+ CategoryInfo : InvalidOperation: (SetPassword:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:18 char:27
+ $objUser.psbase.InvokeSet <<<< ("AccountDisabled",$false)
+ CategoryInfo : InvalidOperation: (InvokeSet:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:19 char:18
+ $objUser.SetInfo <<<< ()
+ CategoryInfo : InvalidOperation: (SetInfo:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
The following exception occurred while retrieving member "create": "There is no such object on the server.
"
At line:10 char:11
+ $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:14
+ $objUser.Put <<<< ("sAMAccountName",$sAMAccountName)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:12 char:14
+ $objUser.Put <<<< ("userPrincipalName",$userPrincipalName)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:13 char:14
+ $objUser.Put <<<< ("displayName",$displayName)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:14 char:14
+ $objUser.Put <<<< ("givenName",$givenName)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:15 char:14
+ $objUser.Put <<<< ("sn",$sn)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:16 char:18
+ $objUser.SetInfo <<<< ()
+ CategoryInfo : InvalidOperation: (SetInfo:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:17 char:22
+ $objUser.SetPassword <<<< ("P@ss123")
+ CategoryInfo : InvalidOperation: (SetPassword:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:18 char:27
+ $objUser.psbase.InvokeSet <<<< ("AccountDisabled",$false)
+ CategoryInfo : InvalidOperation: (InvokeSet:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:19 char:18
+ $objUser.SetInfo <<<< ()
+ CategoryInfo : InvalidOperation: (SetInfo:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
The following exception occurred while retrieving member "create": "There is no such object on the server.
"
At line:10 char:11
+ $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:14
+ $objUser.Put <<<< ("sAMAccountName",$sAMAccountName)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:12 char:14
+ $objUser.Put <<<< ("userPrincipalName",$userPrincipalName)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:13 char:14
+ $objUser.Put <<<< ("displayName",$displayName)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:14 char:14
+ $objUser.Put <<<< ("givenName",$givenName)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:15 char:14
+ $objUser.Put <<<< ("sn",$sn)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:16 char:18
+ $objUser.SetInfo <<<< ()
+ CategoryInfo : InvalidOperation: (SetInfo:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:17 char:22
+ $objUser.SetPassword <<<< ("P@ss123")
+ CategoryInfo : InvalidOperation: (SetPassword:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:18 char:27
+ $objUser.psbase.InvokeSet <<<< ("AccountDisabled",$false)
+ CategoryInfo : InvalidOperation: (InvokeSet:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:19 char:18
+ $objUser.SetInfo <<<< ()
+ CategoryInfo : InvalidOperation: (SetInfo:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
The following exception occurred while retrieving member "create": "There is no such object on the server.
"
At line:10 char:11
+ $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:14
+ $objUser.Put <<<< ("sAMAccountName",$sAMAccountName)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:12 char:14
+ $objUser.Put <<<< ("userPrincipalName",$userPrincipalName)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:13 char:14
+ $objUser.Put <<<< ("displayName",$displayName)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:14 char:14
+ $objUser.Put <<<< ("givenName",$givenName)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:15 char:14
+ $objUser.Put <<<< ("sn",$sn)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:16 char:18
+ $objUser.SetInfo <<<< ()
+ CategoryInfo : InvalidOperation: (SetInfo:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:17 char:22
+ $objUser.SetPassword <<<< ("P@ss123")
+ CategoryInfo : InvalidOperation: (SetPassword:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:18 char:27
+ $objUser.psbase.InvokeSet <<<< ("AccountDisabled",$false)
+ CategoryInfo : InvalidOperation: (InvokeSet:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:19 char:18
+ $objUser.SetInfo <<<< ()
+ CategoryInfo : InvalidOperation: (SetInfo:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
The following exception occurred while retrieving member "create": "There is no such object on the server.
"
At line:10 char:11
+ $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:14
+ $objUser.Put <<<< ("sAMAccountName",$sAMAccountName)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:12 char:14
+ $objUser.Put <<<< ("userPrincipalName",$userPrincipalName)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:13 char:14
+ $objUser.Put <<<< ("displayName",$displayName)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:14 char:14
+ $objUser.Put <<<< ("givenName",$givenName)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:15 char:14
+ $objUser.Put <<<< ("sn",$sn)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:16 char:18
+ $objUser.SetInfo <<<< ()
+ CategoryInfo : InvalidOperation: (SetInfo:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:17 char:22
+ $objUser.SetPassword <<<< ("P@ss123")
+ CategoryInfo : InvalidOperation: (SetPassword:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:18 char:27
+ $objUser.psbase.InvokeSet <<<< ("AccountDisabled",$false)
+ CategoryInfo : InvalidOperation: (InvokeSet:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:19 char:18
+ $objUser.SetInfo <<<< ()
+ CategoryInfo : InvalidOperation: (SetInfo:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
The following exception occurred while retrieving member "create": "There is no such object on the server.
"
At line:10 char:11
+ $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:14
+ $objUser.Put <<<< ("sAMAccountName",$sAMAccountName)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:12 char:14
+ $objUser.Put <<<< ("userPrincipalName",$userPrincipalName)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:13 char:14
+ $objUser.Put <<<< ("displayName",$displayName)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:14 char:14
+ $objUser.Put <<<< ("givenName",$givenName)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:15 char:14
+ $objUser.Put <<<< ("sn",$sn)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:16 char:18
+ $objUser.SetInfo <<<< ()
+ CategoryInfo : InvalidOperation: (SetInfo:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:17 char:22
+ $objUser.SetPassword <<<< ("P@ss123")
+ CategoryInfo : InvalidOperation: (SetPassword:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:18 char:27
+ $objUser.psbase.InvokeSet <<<< ("AccountDisabled",$false)
+ CategoryInfo : InvalidOperation: (InvokeSet:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:19 char:18
+ $objUser.SetInfo <<<< ()
+ CategoryInfo : InvalidOperation: (SetInfo:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
The following exception occurred while retrieving member "create": "There is no such object on the server.
"
At line:10 char:11
+ $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:14
+ $objUser.Put <<<< ("sAMAccountName",$sAMAccountName)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:12 char:14
+ $objUser.Put <<<< ("userPrincipalName",$userPrincipalName)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:13 char:14
+ $objUser.Put <<<< ("displayName",$displayName)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:14 char:14
+ $objUser.Put <<<< ("givenName",$givenName)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:15 char:14
+ $objUser.Put <<<< ("sn",$sn)
+ CategoryInfo : InvalidOperation: (Put:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:16 char:18
+ $objUser.SetInfo <<<< ()
+ CategoryInfo : InvalidOperation: (SetInfo:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:17 char:22
+ $objUser.SetPassword <<<< ("P@ss123")
+ CategoryInfo : InvalidOperation: (SetPassword:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:18 char:27
+ $objUser.psbase.InvokeSet <<<< ("AccountDisabled",$false)
+ CategoryInfo : InvalidOperation: (InvokeSet:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:19 char:18
+ $objUser.SetInfo <<<< ()
+ CategoryInfo : InvalidOperation: (SetInfo:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull