<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Calazan.com &#187; Active Directory</title>
	<atom:link href="http://www.calazan.com/tag/active-directory/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.calazan.com</link>
	<description>Share the Knowledge</description>
	<lastBuildDate>Sun, 05 Sep 2010 00:59:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to query Active Directory using SQL Server</title>
		<link>http://www.calazan.com/querying-active-directory-using-sql-server/</link>
		<comments>http://www.calazan.com/querying-active-directory-using-sql-server/#comments</comments>
		<pubDate>Mon, 25 Aug 2008 22:54:14 +0000</pubDate>
		<dc:creator>webmaster</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[How-To]]></category>
		<category><![CDATA[SysAdmin]]></category>
		<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[ADSI]]></category>

		<guid isPermaLink="false">http://www.calazan.com/querying-active-directory-using-sql-server/</guid>
		<description><![CDATA[Here is one of those things that I wish I had known much sooner.  Very useful and a big time saver.  I just found out about this a few months ago when I wanted to run a report against AD to see if the account info are consistent and up to date, to see which [...]]]></description>
			<content:encoded><![CDATA[<p>Here is one of those things that I wish I had known much sooner.  Very useful and a big time saver.  I just found out about this a few months ago when I wanted to run a report against AD to see if the account info are consistent and up to date, to see which accounts have passwords set to never expire, when they were created/last updated, etc.</p>
<p>So I asked myself whether it&#8217;s possible to query AD directly from SQL.  The first thing I did was do a search on Google of course and sure enough I found this <a title="Querying AD from SQL Server" href="http://blogs.officezealot.com/mauro/archive/2007/10/25/20607.aspx" target="_blank">website</a> with instructions on how to do it!</p>
<p>Here are the steps:</p>
<p><strong>1.</strong> Create a linked server to AD using this command in Query Analyzer:</p>
<p><em>sp_addlinkedserver &#8216;ADSI&#8217;, &#8216;Active Directory Service Interfaces&#8217;, &#8216;ADSDSOObject&#8217;, &#8216;adsdatasource&#8217; </em></p>
<p><strong>2.</strong> Create views using the example below, I&#8217;m calling them vADUsers and vADGroups (replace <strong>calazan</strong> and <strong>com</strong> with <strong>your domain</strong>, add more AD attributes to the view as needed):</p>
<p><em>CREATE VIEW vADUsers AS<br />
SELECT *<br />
FROM OPENQUERY (ADSI,<br />
&#8216;SELECT co, whenCreated, whenChanged, sAMAccountName, sn, givenName, displayName, mail, telephoneNumber, mobile,<br />
physicalDeliveryOfficeName, facsimileTelephoneNumber, title, department, company, manager, ipPhone, userAccountControl, badPwdCount<br />
FROM &#8221;LDAP://DC=calazan,DC=com&#8221;<br />
WHERE objectCategory = &#8221;Person&#8221; AND objectClass = &#8221;user&#8221;&#8217;)</em></p>
<p><em>CREATE VIEW vADGroups AS<br />
SELECT *<br />
FROM OPENQUERY (ADSI,<br />
&#8216;SELECT displayName, groupType, mail, name, info, whenChanged, whenCreated<br />
FROM &#8221;LDAP://DC=calazan,DC=com&#8221;<br />
WHERE objectClass = &#8221;group&#8221;&#8217;)</em></p>
<p><strong>3.</strong> Query the views just like you&#8217;re querying a normal SQL table:</p>
<p align="center"><a href="http://www.calazan.com/wp-content/uploads/2008/08/queryad.jpg"><img class="aligncenter size-medium wp-image-92" title="Querying Active Directory using MS SQL Server 2005" src="http://www.calazan.com/wp-content/uploads/2008/08/queryad.jpg" alt="" width="300" height="177" /></a></p>
<p>I also recommend that you <a title="ADSI Edit download" href="http://www.microsoft.com/downloads/details.aspx?FamilyID=49ae8576-9bb9-4126-9761-ba8011fabf38&amp;displaylang=en" target="_blank">download the free ADSI Edit tool</a> (adsiedit.msc) to see all the attributes available in your Active Directory site.  Microsoft Office Communications Server 2007 and Exchange Server 2007 for example extend the AD schema and you might want to query some of those extra attributes as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.calazan.com/querying-active-directory-using-sql-server/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
