settingsLogin | Registersettings
Es tu primera visita? Te invitamos a visitar nuestra sección de preguntas frecuentes FAQ!
x
Show Menu

modificar masivamente el campo employee id a partir de sus nombres y apellidos ?

0 votos
Amigos , alguna idea de actualizar o modificar masivamente el campo employeeid , considerando los nombres y apellidos .

e intentado modificar este script pero sin exito.

http://gallery.technet.microsoft.com/scriptcenter/e9bafc1a-b5b1-4663-8e25-b0d0ea28c2b2

Tengo Windows Server 2008 R2 .

A la espera de sus comentarios.
por  

1 Respuesta

0 votos

El script esta bien, quiza no tengas las columnas que esta buscando el script dentro del CSV, chequea esto...

O sea debe existir la columna UserName y employeeID, y esta ultima columna la tienes que formatear a mano con excel para que plasme el resultado que quieras tengan los usuarios como ID en el AD.

si no funciona prueba con este:

Option Explicit

Const ForReading        = 1
Const ForAppending      = 8
Const ADS_SCOPE_SUBTREE = 2

Dim WshShell
Dim WshSysEnv
Dim objFSO
Dim WshNetwork
Dim objConnection
Dim objCommand
Dim objRecordSet
Dim objTextFile
Dim objLogFile
Dim objUser
Dim strDN

Dim strDomain
Dim strLogFile
Dim TextFile
Dim strLine
Dim aUsers
Dim i
Dim strMsg
Dim strEmpID

strDomain  = "dc=LACCD,dc=TEST"
TextFile   = "C:\work.csv"
strLogFile = "C:\logerror.log"

Set WshShell    = WScript.CreateObject("WScript.Shell")
Set WshSysEnv   = WshShell.Environment("SYSTEM")
Set objFSO      = CreateObject("Scripting.FileSystemObject")
Set WshNetwork  = WScript.CreateObject("WScript.Network")
Set objTextFile = objFSO.OpenTextFile(TextFile, ForReading)
Set objLogFile  = objFSO.OpenTextFile(strLogFile,ForAppending,True)

objLogFile.WriteLine(Now & ": UpdateEmpID.vbs started")

'----------------------------------------------------------------

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand    = CreateObject("ADODB.Command")

objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

'-----------------------------------------------------------------

'This section deals with the CSV file

Do While Not objTextFile.AtEndOfStream
strLine = Trim(objTextFile.ReadLine)
If inStr(strLine, ",") Then
  aUsers = Split(strLine, ",")
  For i = 0 To UBound(aUsers)
   aUsers(i) = Trim(aUsers(i))
  Next
  'Wscript.Echo ""
  'Wscript.Echo "First Name...: " & aUsers(0)
  'Wscript.Echo "Last Name....: " & aUsers(1)
  'Wscript.Echo "UserName.....: " & aUsers(2)
  'Wscript.Echo "Employee ID..: " & aUsers(3)
 
 
  'This section deals with searching AD for the user account
  'It takes the username (sAMAccountName), AKA the fourth field and actually searches AD for that user account.
  'Then pulls the users Distinguished Name out of that account once it finds it.
  'Then it uses that DN to bind to the account and set the description field.
 
  On Error Resume Next
 
  objCommand.CommandText = _
  "SELECT distinguishedName, givenName, sn FROM 'LDAP://" & strDomain & "'" & _
  " WHERE objectCategory = 'user' " & _
  "   AND sAMAccountName = '" & aUsers(2) & "'"
  Set objRecordSet = objCommand.Execute
 
  objRecordSet.MoveFirst
  strDN = "?????"
  Do Until objRecordSet.EOF
   If  UCase(Trim(aUsers(0))) = UCase(Trim(objRecordSet.Fields("givenName").Value)) _
   And UCase(Trim(aUsers(1))) = UCase(Trim(objRecordSet.FIelds("sn").Value)) Then
   strDN = objRecordSet.Fields("distinguishedName").Value
   End If
   objRecordSet.MoveNext
  Loop
 
  On Error Goto 0
 
  'This section takes the info provided from the AD search above to attach to the user and set the description
  If strDN = "?????" Then
   strMsg = "User not found or names don't match for Username = " & aUsers(2)
   WScript.Echo strMsg
   objLogFile.WriteLine(strMsg)
  Else
   Set objUser = GetObject("LDAP://" & strDN)
   'strMsg = "Script connects to AD"
   'WScript.Echo strMsg
   'WScript.Echo objUser.Name & "'s account updated in AD"
   On Error Resume Next
   strEmpID = objUser.EmployeeID
   If strEmpID = "" Then
    objUser.Put "EmployeeID", aUsers(3)
    strMsg = "Employee Id inserted for: " & aUsers(2)
    objLogFile.WriteLine(strMsg)
    objUser.SetInfo
    If Err.Number <> 0 Then
     strMsg = "Failed to update EmployeeID for Username: " & aUsers(2)
     WScript.Echo strMsg
     objLogFile.WriteLine(strMsg)
     Err.Clear
    Else
     strMsg = objUser.Name & "'s account updated in AD"
     'WScript.Echo strMsg
     objLogFile.WriteLine(strMsg)
    End If
   ElseIf strEmpID <> aUsers(3) Then
    strMsg = "EmployeeID difference for Username: " & aUsers(2) & " in AD: " & strEmpID & " in CSV: " & aUsers(3)
    WScript.Echo strMsg
    objLogFile.WriteLine(strMsg)
   ElseIf strEmpID = aUsers(3) Then
    strMsg = "EmployeeID match for Username: " & aUsers(2) & " in AD: " & strEmpID & " in CSV: " & aUsers(3)
    WScript.Echo strMsg
    objLogFile.WriteLine(strMsg)   
   End If
   On Error GoTo 0  
  End If
End If
Loop
objLogFile.WriteLine(Now & ": UpdateEmpID.vbs stopped")
objLogFile.Close
objTextFile.Close
por (4.6k puntos)  
lo ejecuto y te comento como me va , gracias Gustavo
Rodrigo ,
1. En el excel con formato .csv que columnas se debe considerar ?
2. Te comento que mi objetivo es trabajar con un powerShell o Visual Script  que considere 3 columnas en excel , tales como :
sn                           , givenName             , employeeID
Pedro raul              , Gallardo Rojas       , 34254
Maria Fernanda     , Martinez Caceres   , 34255
Marcos Julios         , Peralta Miranda       , 34256

3. El PowerShell o Visual Script debe actualizar unicamente el campo employeeID segun el formato del excel , teniendo como constantes los campos sn y givenName del excel .

He intentado con el script adjunto pero sin exito.
Espero me puedas apoyar, gracias
...