PowerShell脚本AD用户的空例外

时间:2015-01-27 08:25:57

标签: powershell

这是脚本

$aryUser= import-csv -Path E:\shares\DATA\Userstest.csv
$Class = "User"
$dc = "dc=gc,dc=dean,dc=local"
$null | skip-null 
foreach($strUser in $aryUser)
{
 $ou ="ou="+ $strUser.OU
 $ADSI = [ADSI]"LDAP://$ou,$dc" 
 $cnuser="cn="+ $($strUser.userName)
 $User = $ADSI.Create($Class,$cnuser)
 $User.put("SamaccountName", $($strUser.SamAccountName))
 $User.setInfo()
 $User.put("userPassword", $($strUser.Password))
 $user.psbase.invokeset("AccountDisabled", "False")
 $User.setInfo()
 $User.put("GivenName", $($strUser.GivenName))
 $User.put("sn", $($strUser.sn))
 $User.put("DisplayName", $($strUser.DisplayName))
 $User.put("description", $($strUser.description))
 $User.put("physicalDeliveryOfficeName", $($strUser.physicalDeliveryOfficeName))
 $User.put("telephoneNumber", $($strUser.telephoneNumber))
 $User.put("mail", $($strUser.mail))
 $User.put("wwwHomePage", $($strUser.wwwHomePage))
 $User.put("streetAddress", $($strUser.streetAddress))
 $User.put("postOfficeBox", $($strUser.postOfficeBox))
 $User.put("l", $($strUser.l))
 $User.put("st", $($strUser.st))
 $User.put("postalCode", $($strUser.postalCode))
 $User.put("c", $($strUser.c))
 $User.put("ipPhone", $($strUser.ipPhone))
 $User.put("Department", $($strUser.Department))
 $User.put("Company", $($strUser.Company))
 $User.setInfo()
}

我经常收到此错误

  <磷>氮       + FullyQualifiedErrorId:CatchFromBaseGetMember

     

您无法在空值表达式上调用方法。在   E:\ Shares \ DATA \ bier.ps1:11 char:32   + $ User.put(&#34; SamaccountName&#34;,$($ strUser.SamAccountName))   + ~~~~~~~~~~~~~~~~~~~~~~~       + CategoryInfo:InvalidOperation:(:) [],RuntimeExceptio       + FullyQualifiedErrorId:InvokeMethodOnNull

     

您无法在空值表达式上调用方法。在   E:\ Shares \ DATA \ bier.ps1:12 char:2   + $ User.setInfo()   + ~~~~~~~~~~~~~~~       + CategoryInfo:InvalidOperation:(:) [],RuntimeExceptio       + FullyQualifiedErrorId:InvokeMethodOnNull

     

您无法在空值表达式上调用方法。在   E:\ Shares \ DATA \ bier.ps1:13 char:30   + $ User.put(&#34; userPassword&#34;,$($ strUser.Password))   + ~~~~~~~~~~~~~~~~~       + CategoryInfo:InvalidOperation:(:) [],RuntimeExceptio       + FullyQualifiedErrorId:InvokeMethodOnNull

     

您无法在空值表达式上调用方法。在   E:\ Shares \ DATA \ bier.ps1:14 char:2   + $ user.psbase.invokeset(&#34; AccountDisabled&#34;,&#34; False&#34;)   + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 〜       + CategoryInfo:InvalidOperation:(:) [],RuntimeExceptio       + FullyQualifiedErrorId:InvokeMethodOnNull

     

您无法在空值表达式上调用方法。

0 个答案:

没有答案