Guys,
I need be able to tell the field that some of the data has a comma in it.
For example, the field Title. It may have something like VP, Finance. With the current code, it thinks it is a seperate field.
Below is my code.
-------------------------------------------------
'Global variables
Dim oContainer
Dim OutPutFile
Dim FileSystem
'Initialize global variables
Set FileSystem = WScript.CreateObject("Scripting.FileSystemObject")
Set OutPutFile = FileSystem.CreateTextFile("c:\email.csv", True)
Set oContainer=GetObject("LDAP://host1:389/OU=IT Dept,DC=test,DC=net")
'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.sn) Then
OutPutFile.Write "," & "Last Name: " & oUser.sn
else
OutPutFile.Write ","
End If
If Not IsEmpty(oUser.givenName) Then
OutPutFile.Write "," & "First Name: " & oUser.givenName
else
OutPutFile.Write ","
End If
If Not IsEmpty(oUser.title) Then
OutPutFile.Write "," & "Title: " & oUser.Title
else
OutPutFile.Write ","
End If
If Not IsEmpty(oUser.sAMAccountName) Then
OutPutFile.Write "," & "User ID: " & oUser.sAMAccountName
else
OutPutFile.Write ","
End If
If Not IsEmpty(oUser.department) Then
OutPutFile.Write "," & "Department: " & oUser.department
else
OutPutFile.Write ","
End If
If Not IsEmpty(oUser.physicalDeliveryOfficeName) Then
OutPutFile.Write "," & "Building/Room: " & oUser.physicalDeliveryOfficeName
else
OutPutFile.Write ","
End If
If Not IsEmpty(oUser.telephoneNumber) Then
OutPutFile.Write "," & "Phone: " & oUser.telephoneNumber
else
OutPutFile.Write ","
End If
If Not IsEmpty(oUser.mail) Then
OutPutFile.Write "," & "Email: " & oUser.mail
else
OutPutFile.Write ","
End If
OutPutFile.Write vbcrlf
Case "organizationalunit" , "container"
EnumerateUsers oUser
End Select
Next
End Sub
I need be able to tell the field that some of the data has a comma in it.
For example, the field Title. It may have something like VP, Finance. With the current code, it thinks it is a seperate field.
Below is my code.
-------------------------------------------------
'Global variables
Dim oContainer
Dim OutPutFile
Dim FileSystem
'Initialize global variables
Set FileSystem = WScript.CreateObject("Scripting.FileSystemObject")
Set OutPutFile = FileSystem.CreateTextFile("c:\email.csv", True)
Set oContainer=GetObject("LDAP://host1:389/OU=IT Dept,DC=test,DC=net")
'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.sn) Then
OutPutFile.Write "," & "Last Name: " & oUser.sn
else
OutPutFile.Write ","
End If
If Not IsEmpty(oUser.givenName) Then
OutPutFile.Write "," & "First Name: " & oUser.givenName
else
OutPutFile.Write ","
End If
If Not IsEmpty(oUser.title) Then
OutPutFile.Write "," & "Title: " & oUser.Title
else
OutPutFile.Write ","
End If
If Not IsEmpty(oUser.sAMAccountName) Then
OutPutFile.Write "," & "User ID: " & oUser.sAMAccountName
else
OutPutFile.Write ","
End If
If Not IsEmpty(oUser.department) Then
OutPutFile.Write "," & "Department: " & oUser.department
else
OutPutFile.Write ","
End If
If Not IsEmpty(oUser.physicalDeliveryOfficeName) Then
OutPutFile.Write "," & "Building/Room: " & oUser.physicalDeliveryOfficeName
else
OutPutFile.Write ","
End If
If Not IsEmpty(oUser.telephoneNumber) Then
OutPutFile.Write "," & "Phone: " & oUser.telephoneNumber
else
OutPutFile.Write ","
End If
If Not IsEmpty(oUser.mail) Then
OutPutFile.Write "," & "Email: " & oUser.mail
else
OutPutFile.Write ","
End If
OutPutFile.Write vbcrlf
Case "organizationalunit" , "container"
EnumerateUsers oUser
End Select
Next
End Sub