Power shell null value

I'm trying to create multiple users at once i create the CSV file and .PS1 file 

when i'm try to execute in powe shell i get this message    (

You cannot call a method on a null-valued expression.
At C:\bin\scripts\addusers.ps1:13 char:13
+ $objUser.Put <<<< ("userPrincipalName",$userPrincipalName)
    + CategoryInfo          : InvalidOperation: (Put:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

any one help me

thank you  

August 27th, 2015 2:37am

Can't see your script.

Free Windows Admin Tool Kit Click here and download it now
August 27th, 2015 3:33am

$objOU=[ADSI]LDAP://OU=01A,OU=Grade01,OU=Classes,OU=HighSchool,OU=SIS,DC=sis,DC=com
$dataSource=import-csv addusers.csv
foreach($dataRecord in $datasource) {
$cn=$dataRecord.FirstName + + $dataRecord.LastName
$sAMAccountName=$dataRecord.FirstName + . + $dataRecord.LastName
$givenName=$dataRecord.FirstName
$sn=$dataRecord.LastName
$sAMAccountName=$sAMAccountName.ToLower()
$displayName=$sn + , + $givenName
$userPrincipalName=$sAMAccountName + @sis.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(123456789)
$objUser.psbase.InvokeSet(AccountDisabled,$false)
$objUser.SetInfo()
}
August 30th, 2015 12:13am

Don't use "Put".  Just assign the values.  This is one of the drawbacks of trying to directly convert bad VBScript code found on the Internet.

I recommend that you look in the repository for tested scripts that create users from a CSV.

Free Windows Admin Tool Kit Click here and download it now
August 30th, 2015 7:20am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics