Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Get phone list from AD and print nicely using PDF or other method

Posted on 2006-11-18
11
Medium Priority
?
251 Views
Last Modified: 2012-08-13
Basically speaking, I need to use VB.Net to read AD account information, extract it, and hand off to a nicely printed solution, like an access report, a pdf document or anything else that would look nice. For a bonus 1000 points, they would like to choose which fields show up on the report, but that's just a bonus. Any ideas would be greatly appreciated.

0
Comment
Question by:Montoya
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
  • +1
11 Comments
 
LVL 13

Expert Comment

by:newyuppie
ID: 17973147
what is AD?
0
 
LVL 19

Author Comment

by:Montoya
ID: 17973547
Active Directory, which is where I'd have to get the users' mailbox information after Exchange 5.5

0
 
LVL 13

Expert Comment

by:newyuppie
ID: 17973651
i believe you would use the System.DirectoryServices to directly access functions that will let you retrieve that info.  here are a couple of links i googled up to get you started:

http://www.vbdotnetheaven.com/UploadFile/johncharles/ActiveDirectoryInVB11122005060642AM/ActiveDirectoryInVB.aspx?ArticleID=a775db4b-3909-4d36-86e2-917b6d693465
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdirectoryservices.asp

when you have the info, to make reports you basically have 2 options: built-in vb net reporting, or third party. vb2005 comes with limited crystal reports reporting. you can also buy tools like XtraReports from devexpress.com to make nice, user customizable reports.

hope this info helps you.
NY
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 19

Author Comment

by:Montoya
ID: 17981838
I was hoping for more guided directions or code, please, if anyone can help with this.
0
 
LVL 13

Expert Comment

by:newyuppie
ID: 17982352
were you hoping we do the work for you too?

read this codeproject link it may suit you:
http://www.codeproject.com/dotnet/activedirquery.asp

i also googled up this: http://www.15seconds.com/Issue/060525.htm
0
 
LVL 19

Author Comment

by:Montoya
ID: 17997958
no, I wasnt hoping you would do the work for me. I was hoping for some guidance, as stated above, or at least the same kind of help I try to provide as a guru in another section in this site, or the kind of help I would expect as a paying customer of this site.

Thanks for the links.

0
 
LVL 13

Expert Comment

by:newyuppie
ID: 17998208
hey im sorry, for personal reasons i was in a very bad mood that day.
wish i could help you more with the issue but i dont know much myself. hope you can make something out from those links
NY
0
 
LVL 19

Author Comment

by:Montoya
ID: 18007509
No problem. We all have our days. :)


If someone else has some insight to this issue, I'd greatly appreciated.
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 18007624
Hi Iammontoya,

Here is a sample that achieves what you want (in principle). You could easily extend this, at present it returns a datatable of people from activedirectory matching part of the cn property.

Imports System.DirectoryServices

....... standard stuff, class etc

    Private Sub GetPhoneBook()
        Dim strMatch As String = "John"
        Dim dtAD As New DataTable
        dtAD.TableName = "Default"
        dtAD.Columns.Add("UserName")
        dtAD.Columns.Add("Email Address")
        dtAD.Columns.Add("Telephone")
        dtAD.Columns.Add("Mobile")
        dtAD.Columns.Add("Fax")
        dtAD.Columns.Add("Title")
        dtAD.Columns.Add("Description")
        dtAD.Columns.Add("Facility")
        dtAD.Columns.Add("Address")
        dtAD.Columns.Add("Town")
        dtAD.Columns.Add("PostCode")
        If Not (strMatch Is Nothing) Then
            GetAD("corp.mydomain.com", dtAD, strMatch) 'specify the ad domain to search here, if multiple domains, can call GetAD() succesive times to return data to the same datatable
            dtAD.DefaultView.Sort = "UserName"
'here we do something with the data, in this case bind it to a datagrid, anything else is up to you.
            grdPeople.DataSource = dtAD
            grdPeople.DataBind()
        End If
    End Sub

    Private Sub GetAD(ByVal Root As String, ByRef dtAD As DataTable, ByVal Match As String)
        Dim strLDAP As String = "LDAP://" & Root
        Dim obDirEntry As DirectoryEntry = New DirectoryEntry(strLDAP)
        Dim srch As DirectorySearcher = New DirectorySearcher(obDirEntry)
        Dim results As SearchResultCollection
        srch.Filter = "(cn=*" & Match & "*)"
        Try
            results = srch.FindAll()
        Catch ex As Exception
            Exit Sub
        End Try
        Dim rstl As SearchResult
        For Each rstl In results
            Dim colProps As System.DirectoryServices.ResultPropertyCollection = rstl.Properties
            Dim aryElements(10) As String
            aryElements(0) = GetElement("displayname", colProps)
            aryElements(1) = "<a href=""mailto:" & GetElement("mail", colProps) & """>" & GetElement("mail", colProps) & "</a>" ' this was used on an asp.net page so converts the email address to a clickable link, probably need to change that for vb.net
            aryElements(2) = GetElement("telephonenumber", colProps)
            aryElements(3) = GetElement("mobile", colProps)
            aryElements(4) = GetElement("facsimiletelephonenumber", colProps)
            aryElements(5) = GetElement("title", colProps)
            aryElements(6) = GetElement("description", colProps)
            aryElements(7) = GetElement("physicaldeliveryofficename", colProps)
            aryElements(8) = GetElement("streetaddress", colProps)
            aryElements(9) = GetElement("l", colProps)
            aryElements(10) = GetElement("postalcode", colProps)
            If GetElement("objectClass", colProps).IndexOf("computer") < 0 And aryElements(0).Length > 0 Then
                dtAD.Rows.Add(aryElements)
            End If
        Next
    End Sub

    Private Function GetElement(ByVal Key As String, ByRef Props As ResultPropertyCollection) As String
        Try
            If Props(Key) Is Nothing Then
                Return ""
            Else
                Dim aryProp() As String
                ReDim aryProp(Props.Item(Key).Count - 1)
                Props.Item(Key).CopyTo(aryProp, 0)
                Return Join(aryProp, vbCrLf)
            End If
        Catch ex As Exception
            Return ""
        End Try
    End Function

Tim Cottee
0
 
LVL 1

Expert Comment

by:wpgatrel
ID: 18009676
Here is a simple VBScript that will read ALL user accounts in Active Directory and place the following items into a CSV file.  It will place the CSV file in the same location of the script.  You can use Excel to manipulate it and print it the way you want.

First Name, Last Name, Network Login, E-Mail Address, Telephone Number

'Script Start
Const ADS_SCOPE_SUBTREE = 2
CONST ForReading = 1, ForWriting = 2, ForAppending = 8

Dim DomainName, ParentDir, Server, Lengthy, Lengthy2, Drive, szGivenName, szSN
Dim Command1, WSHNetwork, FS, Domain, DomainObj, Computer, ShareServiceObj, Hidden, DrivePath, nReturnCode

Set objFSO = CreateObject("scripting.FileSystemObject")

LogFile="ContactInfo.CSV"

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

strDNSDomain = objRootDSE.Get("DefaultNamingContext")

Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = "Select * from 'LDAP://" & strDNSDomain & "' Where objectClass='User'"  
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst

set f = objFSO.OpenTextFile(LogFile, ForWriting, True, -2)

f.writeline "First Name,Last Name,Network Login,Email Address,Telephone"

Do Until objRecordSet.EOF


      szSamAccountName = objRecordSet.Fields("samAccountName").Value
      szGivenName = objRecordSet.Fields("GivenName").Value
      szSN = objRecordSet.Fields("SN").Value
      szCN = "CN=" & szGivenName & " " & szSN

      f.writeline szGivenName & "," & szSN & "," & szSamAccountName & "," & Email & "," & telephone

      
objRecordSet.MoveNext
Loop

f.close

wscript.echo "Script Complete!"
'Script Complete
0
 
LVL 1

Accepted Solution

by:
wpgatrel earned 2000 total points
ID: 18009698
Doh!  I meant to paste in THIS code.

'Script Start
Set objFSO = CreateObject("scripting.FileSystemObject")

LogFile="ContactInfo.CSV"

Set objRootDSE = GetObject("LDAP://RootDSE")
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

strDNSDomain = objRootDSE.Get("DefaultNamingContext")

Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = "Select samAccountName, GivenName, SN, telephonenumber, mail from 'LDAP://" & strDNSDomain & "' Where objectClass='User'"  
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst

set f = objFSO.OpenTextFile(LogFile, ForWriting, True, -2)

f.writeline "First Name,Last Name,Network Login,Email Address,Telephone"

Do Until objRecordSet.EOF

      szSamAccountName = objRecordSet.Fields("samAccountName").Value
      szGivenName = objRecordSet.Fields("GivenName").Value
      szSN = objRecordSet.Fields("SN").Value
      szMail = objRecordSet.Fields("Mail").Value
      szTelephoneNumber = objRecordSet.Fields("TelephoneNumber").value

      f.writeline szGivenName & "," & szSN & "," & szSamAccountName & "," & szMail & "," & sztelephoneNumber

      
objRecordSet.MoveNext
Loop

f.close

wscript.echo "Script Complete!"
'Script End
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question