Criando usuários a partir de um arquivo csv no PowerShell

1

É minha primeira vez no PowerShell para criar usuários a partir de um arquivo csv. Eu estou usando um código de um tutorial que eu assisti, ele está trabalhando no quando demonstrado no vídeo, mas eu não consigo fazer isso funcionar ...

$ou=[ADSI] "LDAP:/..."
$dataSource = import-csv ".."

foreach($dataRecord in $dataSource) 
{

  $cn = $dataRecord.cn
  $sAMAccountName = $dataRecord.sAMAccountName
  $givenName = $dataRecord.FirstName
  $sn = $dataRecord.LastName
  $displayName = $sn + ", " + $givenName
  $userPrincipalName = $givenName + "." + $sn + "@nuggetlab.com"
  $newUser =  $ou.Create("user", "cn=" + $cn)

  $newUser.Put("sAMAccountName", $sAMAccountName)
  $newUser.Put("userPrincipalName", $userPrincipalName)
  $newUser.Put("displayName", $displayName)
  $newUser.Put("givenName", $givenName)
  $newUser.SetInfo()
  $newUser.SetPassword("Password")
  $newUser.psbase.InvokeSet("AccountDisabled", $false)
  $newUser.Put("company", "The Fantastic Four")
  $newUser.SetInfo()
}

O erro diz:

Exception calling "SetInfo" with "0" arguments(s): "The specified directory service or value does not exist"
At C:\Users\Administrator\Documents\CreateGroup.ps1:18 char18
+   $newUser.SetInfo <<<< ()
  + CategoryInfo          : NotSpecified: (:) [], MehthodInvocationException
  + FullyQualifiedErrorId : CatchFromBaseAdapterMethodInvokeTI
    
por antonio 20.02.2012 / 10:30

1 resposta

2

$ou=[ADSI] "LDAP:/..."
$dataSource = import-csv ".."

foreach($dataRecord in $dataSource) 
{

  $cn = $dataRecord.cn
  $sAMAccountName = $dataRecord.sAMAccountName
  $givenName = $dataRecord.FirstName
  $sn = $dataRecord.LastName
  $displayName = $sn + ", " + $givenName
  $userPrincipalName = $givenName + "." + $sn + "@nuggetlab.com"
  $newUser =  $ou.Create("user", "cn=" + $cn)

  $newUser.Put("sAMAccountName", $sAMAccountName)
  $newUser.Put("userPrincipalName", $userPrincipalName)
  $newUser.Put("displayName", $displayName)
  $newUser.Put("givenName", $givenName)
  $newUser.SetInfo()
  $newUser.SetPassword("Password")
  $newUser.psbase.InvokeSet("AccountDisabled", $false)
  $newUser.Put("company", "The Fantastic Four")
  $newUser.SetInfo()
}
    
por 22.02.2012 / 02:31

Tags