In my quest to find a way to automate signatures in Office 365 I needed to somehow get the user Attributes synced. Whilst searching I stumbled on the Company Directory. Basically, it reads all the information from your AD that you specify and populates a webpage. Since IT needs to keep that data up to date in any case, I implemented this as an additional feature.
The code is not mine and you can get the original code done by Geoff Kendal of 4sysops.com. I have made slight changes to the code to suit this environment. A word of caution I am not a Programmer or Developer so if there is more code than what is required this is the code that worked for me. I am sure that if you have a bit of knowledge on HTML and ASP you can get very creative in making the site work better for your Environment.
So first things first make sure your web server is able to read ASP. For this, I used a Windows IIS server and installed the ASP feature. As per Screenshot:
Then Created a Folder in “C:\inetpub\wwwroot\” and Named it “TheDirectory” within this folder you can create a file Named “Directory.asp”
And lastly in IIS set the default Document and add directory.asp
Now that this is done. Edit the file directory.asp which was created previously. Browse down to the Script and Copy and past the Script in the file and Save.
The Changes
AD Connection
The Changes you need to make within the following lines are to make the connection with the Active Directory. This needs to be an account that is allowed to read through the Active Directory.
usersOU= “LDAP://””
objCon.Properties(“User ID”) = “DOMAIN\administrator”
objCon.Properties(“Password”) = “Your Very Secure Password”
The Attributes
Then the below is the attributes in the Active Directory. Once you put your AD in Advance mode (Browse to View then Advanced Features). You will see which Attributes are available for use in the attribute Editor Tab. Remember to adjust the headers to correspond to the attributes you use.
Response.Write “<td>” + objRS(“givenName”) + “</td>”
Multiple OU’s
Lastly, you will see I have the code twice, this is if you have users in different OU on the AD.
If you don’t then drop the second code section between <% & %> If you have more than two copy and paste the second Code Snippet, Just remember the more code there is to run the longer it will take to run.
The Script
<%@ Language=VBScript %>
<% response.Buffer = True %>
<html><head>
<title>Company directory</title>
</head>
<body>
<h1><img src=”http://sig.forflukesake.co.za/images/logo.jpg” > <br>Company Directory</h1>
‘ First OU Search
<%
‘ Define the AD OU that contains our users
usersOU = “LDAP://OU=Office365Users,OU=FlukenUsers,OU=User Accounts,DC=ForFlukeSake,DC=co,DC=za”
‘ Make AD connection and run query
Set objCon = Server.CreateObject(“ADODB.Connection”)
objCon.provider =”ADsDSOObject”
objCon.Properties(“User ID”) = “DOMAIN\administrator”
objCon.Properties(“Password”) = “Your Very Secure Password”
objCon.Properties(“Encrypt Password”) = TRUE
objCon.open “Active Directory Provider”
Set objCom = CreateObject(“ADODB.Command”)
Set objCom.ActiveConnection = objCon
objCom.CommandText =”select givenName,sn,ipPhone,mail,title,telephonenumber,mobile FROM ‘”+ usersOU +”‘ where sAMAccountname=’*’ ORDER by sAMAccountname”
Set objRS = objCom.Execute
‘ Add the Headers to the table
Response.Write “<table border=’1′>” + vbCrLf
Response.Write “<tr>”
Response.Write “<th> Name </th>”
Response.Write “<th> Surname </th>”
Response.Write “<th> Extension </th>”
Response.Write “<th> Email </th>”
Response.Write “<th> Job Title </th>”
Response.Write “<th> Works Phone Number </th>”
Response.Write “<th>Mobile Number </th>”
Response.Write “</tr>” + vbCrLf
‘ Loop over returned recordset and output HTML
Do While Not objRS.EOF Or objRS.BOF
Response.Write “<tr>”
Response.Write “<td>” + objRS(“givenName”) + “</td>”
Response.Write “<td>” + objRS(“sn”) + “</td>”
Response.Write “<td>” + objRS(“ipPhone”) + “</td>”
Response.Write “<td>” + objRS(“mail”) + “</td>”
Response.Write “<td>” + objRS(“title”) + “</td>”
Response.Write “<td>” + objRS(“telephonenumber”) + “</td>”
Response.Write “<td>” + objRS(“mobile”) + “</td>”
Response.Write “</tr>” + vbCrLf
objRS.MoveNext
Response.Flush
Loop
‘ Clean up
objRS.Close
objCon.Close
Set objRS = Nothing
Set objCon = Nothing
Set objCom = Nothing
%>
‘ Second OU Search
<%
‘ Define the AD OU that contains our users
usersOU = “LDAP://OU=Reps,OU=FlukenUsers,OU=User Accounts,DC=ForFlukeSake,DC=co,DC=za”
‘ Make AD connection and run querySet objCon = Server.CreateObject(“ADODB.Connection”)
objCon.provider =”ADsDSOObject”
objCon.Properties(“User ID”) = “DOMAIN\administrator”
objCon.Properties(“Password”) = “Your Very Secure Password!”
objCon.Properties(“Encrypt Password”) = TRUE
objCon.open “Active Directory Provider”
Set objCom = CreateObject(“ADODB.Command”)
Set objCom.ActiveConnection = objCon
objCom.CommandText =”select givenName,sn,ipPhone,mail,title,telephonenumber,mobile FROM ‘”+ usersOU +”‘ where sAMAccountname=’*’ ORDER by sAMAccountname”
Set objRS = objCom.Execute
‘ Loop over returned recordset and output HTML
Do While Not objRS.EOF Or objRS.BOF
Response.Write “<tr>”
Response.Write “<td>” + objRS(“givenName”) + “</td>”
Response.Write “<td>” + objRS(“sn”) + “</td>”
Response.Write “<td>” + objRS(“ipPhone”) + “</td>”
Response.Write “<td>” + objRS(“mail”) + “</td>”
Response.Write “<td>” + objRS(“title”) + “</td>”
Response.Write “<td>” + objRS(“telephonenumber”) + “</td>”
Response.Write “<td>” + objRS(“mobile”) + “</td>”
Response.Write “</tr>” + vbCrLf
objRS.MoveNext
Response.Flush
Loop
‘ Clean up
objRS.Close
objCon.Close
Set objRS = Nothing
Set objCon = Nothing
Set objCom = Nothing
%>
</table>
</body>
</html>