Exportar la información de usuario de Directorio Activo

A un ficherito csv separado por comas.

Visual Basic

'* description: export users from Active Directory to a comma separated text file.
'*  Use the text file to create users in a new AD with the accompanying import script.
'*              
'* author: Chris Pilling
'* date: 18 June 2008
'* edit the attributes exported to suit
'* after running it is probably best to delete lines from the text file for system generated accounts
 
Const ForAppending = 8
 
Set objRoot = GetObject("LDAP://RootDSE") 
strDNC = objRoot.Get("DefaultNamingContext") 
Set objDomain = GetObject("LDAP://" & strDNC)
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("C:\AD_Users_Export.txt")
 
Call enummembers(objDomain) 
Sub enumMembers(objDomain) 
On Error Resume Next 
 
For Each objMember In objDomain  
 
If ObjMember.Class = "user" Then
 
'* edit the attributes you want to export here  
 
If Not (isempty(ObjMember.samAccountName)) Then 
    SamAccountName = ObjMember.samAccountName 
else 
    SamAccountName = "" 
End If
If Not (isempty(ObjMember.CN)) Then Cn = ObjMember.CN else Cn = "" End If
If Not (isempty(objMember.GivenName)) Then FirstName =objMember.GivenName else FirstName = "" End If
If Not (isempty(objMember.sn)) Then Lastname = ObjMember.sn else LastName = "" End If
If Not (isempty(objMember.UserPrincipalName)) Then 
    UserPrincipalName = objMember.UserPrincipalName 
    else 
    Name = "" 
End If
If Not (isempty(objMember.ProfilePath)) Then 
    ProfilePath = objMember.profilePath 
else 
    Profile = "" 
End If
If Not (isempty(ObjMember.homeDrive)) Then homeDrive = ObjMember.homeDrive else homeDrive = "" End If
If Not (isempty(ObjMember.homeDirectory)) Then 
    homeDirectory = ObjMember.homeDirectory 
else 
    homeDirectory = "" 
End If
If Not (isempty(ObjMember.Scriptpath)) Then 
    LoginScript = ObjMember.Scriptpath 
else 
    LoginScript = "" 
End If
 
set objFolder = nothing
set objFile = nothing
 
Set objTextFile = objFSO.OpenTextFile ("d:\AD_Users_Export.txt", ForAppending, True)
 
wscript.echo SamAccountName & "," & CN & "," & FirstName & "," & LastName & "," & UserPrincipalName & _
    "," & ProfilePath & ","  Homedrive & "," & Homedirectory & "," & LoginScript
 
strText1 = SamAccountName & "," & CN & "," & FirstName & "," & LastName & "," & UserPrincipalName & _
    "," & ProfilePath & "," & homedrive & "," & Homedirectory & "," & LoginScript

objTextFile.WriteLine(strText1) 
objTextFile.Close
 
End If 
  
If objMember.Class = "organizationalUnit" or OBjMember.Class = "container" Then 
enumMembers (objMember) 
End If 
Next 
End Sub
Anuncios

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión /  Cambiar )

Google photo

Estás comentando usando tu cuenta de Google. Cerrar sesión /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión /  Cambiar )

Conectando a %s