Windows, Linux, КПК и немного ещё.

Address book in html from AD

ru: Адресная книга в html из AD

Somehow historically it happened that the address book in the organization was kept in an Excel file lying on the share. But there is a wonderful Active Directory in which all the data is there! I saved the employee from the heavy burden of bringing everyone into the file and made a knee-pad script in a couple of minutes. Well, the template, in another couple of tens of minutes bungled. We just run the script and we have html, which can be put anywhere, and politicians add it to the bookmarks of all employees.

GitHub link

addressbook.ps1:

PowerShell
$curDir = $MyInvocation.MyCommand.Definition | split-path -parent 
$searchBase = "OU=users,DC=company,DC=com"
$LDAPFilter = "(&(objectCategory=Person)(objectClass=User)(mail=*)(givenName=*)(sn=*)(!userAccountControl:1.2.840.113556.1.4.803:=2))" # незаблокированные юзеры с емейлом и заполненными именем-фамилией
$tplFile = $curDir + "\addressbook.tpl" #файл с темплейтом
$outFile = "\\iiswebserver\spravochnik\index.html" # куда кладём сгенерённый файл.
$UserCount = 0
$dt=Get-Date -Format "yyyy-MM-dd HH:mm"
 
$TextContent = ""
 
import-module ActiveDirectory
 
$users = Get-ADUser -LDAPFilter $LDAPFilter -SearchBase $searchBase -SearchScope Subtree -Properties cn, displayName, telephoneNumber, ipPhone, mail, Department, Title, Office
foreach ($user in $users) {
	$TextContent = $TextContent+"<tr><td>"+$user.displayName+"</td><td>"+$user.telephoneNumber+"</td><td>"+$user.ipPhone+"</td><td><a href=`"mailto:"+$user.mail+"`">"+$user.mail+"</a></td><td>"+$user.Title+"</td><td>"+$user.Department+"</td><td>"+$user.Office+"</td></tr>`n"
	$UserCount++
}
 
$tplText = Get-Content $tplFile -Encoding UTF8
$tplText = $tplText -replace "__content__", $TextContent
$tplText | Out-File $outFile -Encoding UTF8
 
Write-Host "$dt - done. $UserCount users exported."

addressbook.tpl:

html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Адресная книга "Рога и Копыта"</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
 
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css">
<link rel="stylesheet" href="https://cdn.datatables.net/fixedheader/3.1.2/css/fixedHeader.dataTables.min.css">
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/fixedheader/3.1.2/js/dataTables.fixedHeader.min.js"></script>
<style type="text/css">
div.container {
width: 95%;
}
div#addressbook_filter {
float: left;
text-align: left;
}
</style>
<script>
$(document).ready(function() {
var table = $('#addressbook').DataTable( {
paging: false,
fixedHeader: {
 header: true,
 footer: false
 },
language: {
 info: "Показано _END_ записей",
 infoFiltered: "(отфильтровано из _MAX_ записей)",
 search: "Поиск: "
 }
} );
} );
</script>
</head>
 
<body>
<div class="container">
<div class="table-responsive">
<table class="display" id="addressbook" cellspacing="0" width="100%">
<thead>
<tr><th>ФИО</th><th>Телефон</th><th>добавочный</th><th>e-mail</th><th>Должность</th><th>Отдел</th><th>Кабинет</th></tr>
</thead>
<tbody>
__content__
</tbody>
</table>
</div>
</div>
</body>
</html>

comments powered by Disqus