Hi,
I have this script which outputs the username and email address of users from our AD into a txt file.
I would like the output to be in .csv format. Can anyone help me modify the script.
Thanks in advance.
Kachbo.
'Global variables
Dim oContainer
Dim OutPutFile
Dim FileSystem
'Initialize global variables
Set FileSystem = WScript.CreateObject("Scripting.FileSystemObject")
Set OutPutFile = FileSystem.CreateTextFile("c:\email.txt", True)
Set oContainer=GetObject("LDAP://ou=Departments,DC=ad,DC=hackney,DC=gov,DC=uk")
'Enumerate Container
EnumerateUsers oContainer
'Clean up
OutPutFile.Close
Set FileSystem = Nothing
Set oContainer = Nothing
WScript.Echo "Finished"
WScript.Quit(0)
Sub EnumerateUsers(oCont)
Dim oUser
For Each oUser In oCont
Select Case LCase(oUser.Class)
Case "user"
'If Not IsEmpty(oUser.distinguishedName) Then
'OutPutFile.WriteLine "dn: " & oUser.distinguishedName
'End If
If Not IsEmpty(oUser.name) Then
OutPutFile.WriteLine "name: " & oUser.Get ("name")
End If
'need to do this because oUser.name would get back the Relative Distinguished name (i.e. CN=Jo Brown)
'If Not IsEmpty(oUser.st) Then
'OutPutFile.WriteLine "st: " & oUser.st
'End If
If Not IsEmpty(oUser.mail) Then
OutPutFile.WriteLine "mail: " & oUser.mail
End If
Case "organizationalunit" , "container"
EnumerateUsers oUser
End Select
OutPutFile.WriteLine
Next
End Sub
I have this script which outputs the username and email address of users from our AD into a txt file.
I would like the output to be in .csv format. Can anyone help me modify the script.
Thanks in advance.
Kachbo.
'Global variables
Dim oContainer
Dim OutPutFile
Dim FileSystem
'Initialize global variables
Set FileSystem = WScript.CreateObject("Scripting.FileSystemObject")
Set OutPutFile = FileSystem.CreateTextFile("c:\email.txt", True)
Set oContainer=GetObject("LDAP://ou=Departments,DC=ad,DC=hackney,DC=gov,DC=uk")
'Enumerate Container
EnumerateUsers oContainer
'Clean up
OutPutFile.Close
Set FileSystem = Nothing
Set oContainer = Nothing
WScript.Echo "Finished"
WScript.Quit(0)
Sub EnumerateUsers(oCont)
Dim oUser
For Each oUser In oCont
Select Case LCase(oUser.Class)
Case "user"
'If Not IsEmpty(oUser.distinguishedName) Then
'OutPutFile.WriteLine "dn: " & oUser.distinguishedName
'End If
If Not IsEmpty(oUser.name) Then
OutPutFile.WriteLine "name: " & oUser.Get ("name")
End If
'need to do this because oUser.name would get back the Relative Distinguished name (i.e. CN=Jo Brown)
'If Not IsEmpty(oUser.st) Then
'OutPutFile.WriteLine "st: " & oUser.st
'End If
If Not IsEmpty(oUser.mail) Then
OutPutFile.WriteLine "mail: " & oUser.mail
End If
Case "organizationalunit" , "container"
EnumerateUsers oUser
End Select
OutPutFile.WriteLine
Next
End Sub