<?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>ldap389 &#187; tools</title>
	<atom:link href="http://www.ldap389.info/category/tools/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ldap389.info</link>
	<description>Active Directory Blog</description>
	<lastBuildDate>Thu, 26 Jan 2012 11:37:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Powershell: Inventaire Mobile Blackberry et Activesync sous Exchange</title>
		<link>http://www.ldap389.info/2011/11/18/powershell-sql-ems-inventaire-mobile-blackberry-activesync-exchange/</link>
		<comments>http://www.ldap389.info/2011/11/18/powershell-sql-ems-inventaire-mobile-blackberry-activesync-exchange/#comments</comments>
		<pubDate>Thu, 17 Nov 2011 23:09:53 +0000</pubDate>
		<dc:creator>ldap389</dc:creator>
				<category><![CDATA[scripts]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[ActiveSync]]></category>
		<category><![CDATA[BlackBerry]]></category>
		<category><![CDATA[Exchange]]></category>
		<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">http://www.ldap389.info/?p=1495</guid>
		<description><![CDATA[Quand vous mettez en place un solution de messagerie Exchange vous avez la possibilité de permettre à vos utilisateurs d&#8217;accéder à leur boite aux lettres sur leur mobile via le protocole ActiveSync pour la plupart des plateformes (IPhone, Android, Windows Phone&#8230;). En ce qui concerne Blackberry, pour une solution d&#8217;entreprise, il est conseillé de mettre en place une infrastructure [...]]]></description>
			<content:encoded><![CDATA[<p>Quand vous mettez en place un solution de messagerie Exchange vous avez la possibilité de permettre à vos utilisateurs d&#8217;accéder à leur boite aux lettres sur leur mobile via le <a href="http://www.microsoft.com/about/legal/en/us/IntellectualProperty/IPLicensing/Programs/ExchangeActiveSyncProtocol.aspx">protocole ActiveSync</a> pour la plupart des plateformes (IPhone, Android, Windows Phone&#8230;). En ce qui concerne Blackberry, pour une solution d&#8217;entreprise, il est conseillé de mettre en place une infrastructure <a href="http://us.blackberry.com/apps-software/server/exchange/">BES</a>.<br />
<span id="more-1495"></span><br />
Le but de ce script Powershell est de réaliser un inventaire de l&#8217;ensemble des mobiles se connectant à votre messagerie d&#8217;entreprise Exchange. Cela se fait en deux parties: Un inventaire Blackberry en requêtant la base de configuration SQL BES et un inventaire des mobiles utilisant le protocole ActiveSync en requêtant l&#8217;Active Directory:</p>
<p><span style="text-decoration: underline;"><strong>Inventaire BlackBerry:</strong></span></p>
<p>Toutes les informations de configuration de votre solution BES sont stockées dans la base SQL BESMGMT, vous trouverez donc entre autres toutes les informations concernant les mobiles BlackBerry. Pour cela trois tables sont intéressantes:</p>
<ul>
<li>UserConfig: Contient entre autres l&#8217;adresse Email de l&#8217;utilisateur (<em>MailboxSMTPAddr</em>).</li>
<li>SyncDeviceMgmtSummary: Modèle du blackberry et version d&#8217;OS (<em>ModelName</em> et <em>AppsVer</em>).</li>
<li>UserStats: Date du dernier Email reçu (<em>LastFwdTime</em>).</li>
</ul>
<p>En utilisant SQL Management Studio vous pouvez naviguer dans les tables pour retrouver les informations utiles:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2011/11/besmgmt.jpg" rel="lightbox[1495]"><img class="aligncenter size-medium wp-image-1496" title="besmgmt" src="http://www.ldap389.info/wp-content/uploads/2011/11/besmgmt-300x200.jpg" alt="" width="300" height="200" /></a></p>
<p>Il ne vous reste plus qu&#8217;à utiliser PowerShell pour vous connecter à la base SQL et récupérer les informations qui vous sont utiles. La clef commune entre les trois tables est la valeur <em>ID. </em>Nous ne prenons en compte que les BlackBerry ayant reçu un Email au cours des 60 derniers jours.</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$days</span> <span style="color: pink;">=</span> <span style="color: #804000;">60</span>
<span style="color: #800080;">$dbServer</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;SQLBES-SRV&quot;</span>
<span style="color: #800080;">$db</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;BESMgmt&quot;</span>
&nbsp;
<span style="color: #008000;">#If you use SA account to connect database, change pwd=XXXXXX!, or use Windows Authentication, see below</span>
<span style="color: #800080;">$connString</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Server=$dbServer;Database=$db;uid=sa;pwd=XXXXXX&quot;</span>
&nbsp;
<span style="color: #008000;">#If you use Windows Authentication to connect BESMGMT SQL Database, need setup the database</span>
<span style="color: #008000;">#$connString = &quot;Server=$dbServer;Database=$db;Integrated Security=True&quot;</span>
&nbsp;
<span style="color: #008000;">#SQL Query to retrieve BB devices Info (only devices who recieved mail in the last $days)</span>
<span style="color: #800080;">$Query</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Select UserConfig.DisplayName,MailboxSMTPAddr,ModelName,LastFwdTime,AppsVer from UserConfig,SyncDeviceMgmtSummary,UserStats where UserConfig.ID=SyncDeviceMgmtSummary.UserConfigID AND UserConfig.ID=UserStats.UserConfigID AND DeviceType &lt;&gt; 0 AND ModelName &lt;&gt; '' AND DateDiff(dd,LastFwdTime,GETDATE()) &lt; &quot;</span><span style="color: pink;">+</span><span style="color: #800080;">$days</span>
&nbsp;
<span style="color: #008000;">#Connect to Database, run Query, Disconnect</span>
&nbsp;
<span style="color: #800080;">$SqlConnection</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Data.SqlClient.SqlConnection
<span style="color: #800080;">$SqlConnection</span>.ConnectionString <span style="color: pink;">=</span> <span style="color: #800080;">$connString</span>
<span style="color: #800080;">$SqlCmd</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Data.SqlClient.SqlCommand
<span style="color: #800080;">$SqlCmd</span>.CommandText <span style="color: pink;">=</span> <span style="color: #800080;">$Query</span>
<span style="color: #800080;">$SqlCmd</span>.Connection <span style="color: pink;">=</span> <span style="color: #800080;">$SqlConnection</span>
<span style="color: #800080;">$SqlAdapter</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Data.SqlClient.SqlDataAdapter
<span style="color: #800080;">$SqlAdapter</span>.SelectCommand <span style="color: pink;">=</span> <span style="color: #800080;">$SqlCmd</span>
<span style="color: #800080;">$DataSet</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Data.DataSet
<span style="color: #800080;">$SqlAdapter</span>.Fill<span style="color: #000000;">&#40;</span><span style="color: #800080;">$DataSet</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$SqlConnection</span>.Close<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$bbs</span> <span style="color: pink;">=</span> <span style="color: #800080;">$DataSet</span>.Tables<span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span></pre></div></div>

<p>Si vous voulez plus d&#8217;exemples de requêtes SQL sur BES vous pouvez lire ce <a href="http://www.jigsawboys.com/2008/04/04/sql-query-to-exportlist-all-users-in-your-blackberry-server-farm/">post</a> ou bien ce <a href="http://www.blackberryforums.com/bes-admin-corner/178896-powershell-bes.html">forum</a> qui nécessite l&#8217;utilisation des Cmdlets SQL 2008. Le script ci dessus fait appel directement au Namespace <em><a href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.aspx">System.Data.SqlClient</a></em> et ne nécessite que PowerShell v2.</p>
<p>Il ne vous reste plus qu&#8217;à parcourir <em>$bbs </em>pour avoir les informations sur vos clients BlackBerry.</p>
<p><span style="text-decoration: underline;"><strong>Inventaire ActiveSync:</strong></span></p>
<p>En ce qui concerne l&#8217;inventaire de vos autres mobiles se connectant via ActiveSync c&#8217;est plus simple, car l&#8217;information est stockée dans Active Directory. En effet comme l&#8217;indique <a href="http://www.frickelsoft.net/blog/?p=285">Florian&#8217;s blog</a> ces données sont un sous objet de votre compte utilisateur: Pour vous en convaincre, ouvrez une console <em>dsa.msc</em>:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2011/11/activesync-device.jpg" rel="lightbox[1495]"><img class="aligncenter size-medium wp-image-1498" title="activesync-device" src="http://www.ldap389.info/wp-content/uploads/2011/11/activesync-device-300x117.jpg" alt="" width="300" height="117" /></a></p>
<p>Grâce à l&#8217;Exchange Management Shell (2007 et 2010), le cmdlet <em><a href="http://technet.microsoft.com/en-us/library/aa996908(EXCHG.80).aspx">Get-ActiveSyncDeviceStatistics </a></em>permet de fournir très facilement des statistiques sur vos mobiles utilisant ActiveSync: Pour des exemples lire ce post de <a href="http://www.simple-talk.com/sysadmin/exchange/identifying-exchange-activesync-users-with-powershell/">Ben Lye</a> sur le sujet. Les valeurs suivantes sont particulièrement intéressantes:</p>
<ul>
<li>DeviceType: Le type de mobile (ex: Iphone, WP, Android&#8230;)</li>
<li>DeviceModel: Le modèle de mobile (ex: HTC, LG, Samsung, Iphone&#8230;)</li>
<li>DeviceUserAgent: Figure la build de l&#8217;OS (Iphone, WP, Android&#8230;)</li>
<li>LastSuccessSync: Dernière synchronisation ActiveSync réussie, nous filtrons tout comme les BlackBerry, les mobiles ayant répondu au cours des 60 derniers jours.</li>
</ul>
<p>Nous retrouvons donc à peu près les mêmes informations que celles obtenues sur les BlackBerry via notre requête SQL.</p>
<p><span style="text-decoration: underline;"><strong>Fonctionnement général du script:</strong></span></p>
<p>Nous commençons donc par faire un inventaire BlackBerry en requêtant la base SQL BESMGMT. Pour chaque adresse Email <em>MailboxSMTPAddr </em>nous vérifions si il possède aussi un mobile utilisant le protocole ActiveSync (et oui quand on est vraiment VIP on a un BlackBerry et un Ipad <img src='http://www.ldap389.info/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  ), ceci via la commande:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$acts</span> <span style="color: pink;">=</span> Get<span style="color: pink;">-</span>ActiveSyncDeviceStatistics <span style="color: pink;">-</span>Mailbox <span style="color: #800080;">$bb</span>.MailboxSMTPAddr
&nbsp;
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$acts</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Measure-object</span><span style="color: #000000;">&#41;</span>.count <span style="color: #FF0000;">-eq</span> <span style="color: #804000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>User has just one BB no ActiveSync device<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0000FF;">else</span> <span style="color: #000000;">&#123;</span>User has one ActiveSync device <span style="color: #0000FF;">in</span> addition to BB<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Une fois l&#8217;inventaire BlackBerry terminé nous chargeons l&#8217;ensemble des boites aux lettres utilisateur Exchange via la commande:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$Mailboxes</span> <span style="color: pink;">=</span> Get<span style="color: pink;">-</span>Mailbox <span style="color: pink;">-</span>RecipientTypeDetails UserMailbox <span style="color: pink;">-</span>ResultSize Unlimited</pre></div></div>

<p>Puis nous comparons leur <em>PrimarySmtpAddress </em>(récupéré via le cmdlet Get-Mailbox) avec les <em>MailboxSMTPAddr </em>(<em>$BESsmtpArray</em>) afin d&#8217;exclure les utilisateurs déjà traités dans l&#8217;inventaire BlackBerry. Pour ces utilisateurs restants nous vérifions si ils possèdent un mobile utilisant ActiveSync.</p>
<p>Le résultat sort sous la forme d&#8217;un fichier CSV avec les informations suivantes:</p>
<ul>
<li>Adresse Email de l&#8217;utilisateur.</li>
<li>Nombre de mobiles (ActiveSync + BlackBerry).</li>
<li>Type de mobile: BlackBerry, IPhone, WP, Android&#8230;</li>
<li>Modèle du mobile: Modèle de BlackBerry, Samsung, HTC, LG&#8230;</li>
<li>Version d&#8217;OS.</li>
<li>Dernière connexion: Dernier Email reçu sur BlackBerry, dernière synchronisation ActiveSync.</li>
</ul>
<p>Voici un exemple de résultat obtenu:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2011/11/output.jpg" rel="lightbox[1495]"><img class="aligncenter size-medium wp-image-1499" title="output" src="http://www.ldap389.info/wp-content/uploads/2011/11/output-300x65.jpg" alt="" width="300" height="65" /></a></p>
<p>Il vous faudra modifier les paramètres suivants dans le script et le lancer à partir de l&#8217;Exchange Management Shell:</p>
<ul>
<li>$days: Si vous souhaitez alonger ou réduire le seuil d&#8217;inactivité (60 jours par défaut).</li>
<li>$dbServer: Nom de votre serveur SQL BES.</li>
<li>La variable $connString: Selon le type d&#8217;authentification à la base SQL que vous utilisez.</li>
</ul>
<p>Pour télécharger le script complet, c&#8217;est ici:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2011/11/countMobile.ps1"><img class="aligncenter size-full wp-image-83" title="tool" src="http://www.ldap389.info/wp-content/uploads/2010/03/tool1.png" alt="" width="48" height="48" /></a></p>
<p>PS: Le script n&#8217;a été testé que sous Exchange 2010 et BES 5.02, merci de vos retours sur les autres versions. A valider sous Exchange 2007, le cmdlet utilisé étant le même.</p>
<div class="tweetthis" style="text-align:left;"><p> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=Powershell%3A+Inventaire+Mobile+Blackberry+et+Activesync+sous+Exchange+http%3A%2F%2Fis.gd%2FtkqqOt" title="Post to Twitter"><img class="nothumb" src="http://www.ldap389.info/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter-micro3.png" alt="Post to Twitter" /></a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.ldap389.info/2011/11/18/powershell-sql-ems-inventaire-mobile-blackberry-activesync-exchange/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Clickodrome: Histoires de MMC&#8230;</title>
		<link>http://www.ldap389.info/2011/06/11/clickodrome-histoires-mmc-gpmc-dnsmgmt-dsa/</link>
		<comments>http://www.ldap389.info/2011/06/11/clickodrome-histoires-mmc-gpmc-dnsmgmt-dsa/#comments</comments>
		<pubDate>Sat, 11 Jun 2011 12:59:34 +0000</pubDate>
		<dc:creator>ldap389</dc:creator>
				<category><![CDATA[gpo]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[dns]]></category>
		<category><![CDATA[gpmc]]></category>
		<category><![CDATA[mmc]]></category>
		<category><![CDATA[rsop]]></category>
		<category><![CDATA[vbs]]></category>

		<guid isPermaLink="false">http://www.ldap389.info/?p=1182</guid>
		<description><![CDATA[Nous allons dans ce post référencer différents cas intéressants que nous avons pu rencontrer lors de l&#8217;utilisation de notre principal outil de travail: Les consoles de management MS (MMC) , et oui on ne travaille pas tout le temps avec Powershell&#8230; Nous allons parler DNS (dnsmgmt.msc), GPOs (rsop.msc et gpmc.msc) et finalement utilisateurs et ordinateurs [...]]]></description>
			<content:encoded><![CDATA[<p>Nous allons dans ce post référencer différents cas intéressants que nous avons pu rencontrer lors de l&#8217;utilisation de notre principal outil de travail: Les consoles de management MS (MMC) , et oui on ne travaille pas tout le temps avec Powershell&#8230;</p>
<p>Nous allons parler DNS (<em>dnsmgmt.msc</em>), GPOs (<em>rsop.msc</em> et <em>gpmc.msc</em>) et finalement utilisateurs et ordinateurs AD (<em>dsa.msc</em>) et voir quels problèmes nous avons pu rencontrer lors de l&#8217;utilisation de ces consoles, que ce soit sous AD 2000/2003 et AD 2008.<br />
<span id="more-1182"></span></p>
<p><span style="text-decoration: underline;"><strong>DNS</strong></span></p>
<ul>
<li>Vous ne pouvez pas gérer de serveurs DNS Windows 2008R2 avec une console d&#8217;administration DNS (<em>dnsmgmt.msc</em>) sous Windows 2003/XP et versions inférieures, car le niveau de sécurité a été augmenté au niveau RPC, pour plus de détails vous pouvez lire <a href="http://support.microsoft.com/kb/2027440">cette KB</a>. La version 2003/XP de <em>dnscmd.exe</em> n&#8217;est pas compatible non plus: Attention lors de vos migrations de DCs vers 2008R2, vos anciens scripts utilisant la version 2003/XP de <em>dnscmd.exe </em>seront à mettre à jour.</li>
</ul>
<ul>
<li>L&#8217;effacement de <a href="http://social.technet.microsoft.com/Forums/en-US/winserverNIS/thread/38d473d8-ceae-4855-bc97-2c43f9783690">glue records fait freezer</a> la console <em>dnsmgmt.msc</em> sous Windows 2008R2, il vous faudra faire cette manipulation avec <em><a href="http://technet.microsoft.com/en-us/library/cc759561%28WS.10%29.aspx">dnscmd.exe</a></em>.</li>
</ul>
<p><span style="text-decoration: underline;"><strong>GPOs</strong></span></p>
<ul>
<li>Les paramètres de <a href="http://technet.microsoft.com/en-us/library/cc731892(WS.10).aspx">préférences de stratégies de groupe</a> (GPP) n&#8217;apparaissent pas quand vous faites un <em>rsop.msc</em> sur une machine cliente: Par contre, si vous<a href="http://social.technet.microsoft.com/Forums/hu-HU/winserverGP/thread/480dff2a-bb64-4916-b1c5-255d87f1b676"> utilisez la GPMC pour obtenir les paramètres de GPOs </a>appliqués à une machine vous aurez cette information. Pour cela utiliser le <em>Group Policy Results Wizard</em>:</li>
</ul>
<p><img class="aligncenter size-medium wp-image-1189" title="gpmc-rsop" src="http://www.ldap389.info/wp-content/uploads/2011/06/gpmc-rsop-300x245.jpg" alt="" width="300" height="245" /></p>
<p>&nbsp;</p>
<ul>
<li>Vous ne pouvez pas installer la console <em>gpmc.msc</em> sur Windows 2003 x64, pour y <a href="http://blog.freyguy.com/archives/2008/05/04/using-gpmc-group-policy-management-console-on-windows-2003-x64/">arriver il vous faut modifier le package MSI </a>avec un éditeur comme Orca. Les scripts <em>vbs</em> pour manipuler les GPOs ne fonctionneront pas (si quelqu&#8217;un a un solution ?), l&#8217;appel <em>CreateObject(&#8220;GPMGMT.GPM&#8221;) </em>vous retournera l&#8217;erreur:</li>
<blockquote><p>Microsoft VBScript runtime error: ActiveX component can&#8217;t create object: &#8216;GPMGMT.GPM&#8217;</p></blockquote>
<p style="text-align: left;">L&#8217;enregistrement de la DLL <em>gpmgmt.dll</em> ne résout pas le problème.</p>
</ul>
<p><span style="text-decoration: underline;"><strong>Utilisateurs et ordinateurs AD (ADUC ou DSA.MSC)<br />
</strong></span></p>
<p>Lorsque vous utilisez la console <em>dsa.msc</em> avec les RSAT vous avez l&#8217;onglet <em><a href="http://policelli.com/blog/archive/2008/08/28/built-in-attribute-editor-in-windows-server-2008/">attribute editor</a> </em>qui vous permet de vous séparer de votre console <em><a href="http://technet.microsoft.com/en-us/library/bb124152(EXCHG.65).aspx">adsiedit.msc</a>: </em></p>
<ul>
<li>Si vous gérez un AD 2000/2003 avec les RSAT vous ne verrez pas l&#8217;onglet <em>attribute editor</em> apparaitre sans réaliser <a href="http://blogs.dirteam.com/blogs/jorge/archive/2009/08/05/managing-w2k3-ad-domain-through-windows-vista-or-windows-server-2008-r2.aspx">cette manipulation</a>.</li>
<p>&nbsp;</p>
<li>Sous AD 2008 cet onglet apparait dans l&#8217;ADUC, mais lorsque vous éditez un objet suite à une recherche, cet onglet <a href="http://social.technet.microsoft.com/Forums/en-US/winserverManagement/thread/6e6ef6bd-b5c9-4f16-b346-097832e3b93c/">n&#8217;est pas disponible</a>. Par contre si vous utilisez la console <a href="http://blogs.technet.com/b/askds/archive/2011/06/16/fun-with-the-ad-administrative-center.aspx">ADAC</a> (disponible nativement sous 2008R2), cet onglet apparaît bien dans la section &#8220;Extensions&#8221; quand vous faites une recherche sur un objet.</li>
</ul>
<p>Malgré ces quelques comportements bizarres on continue a se servir de nos MMC qui nous facilitent bien la vie, sinon on aurait plus que du <a href="http://msdn.microsoft.com/en-us/library/ms723891(v=vs.85).aspx">Windows Server Core</a> <img src='http://www.ldap389.info/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> , ce qui nous ferait gagner <a href="http://technet.microsoft.com/en-us/library/cc753802(WS.10).aspx">un peu de stockage</a>&#8230; (voir chapitre <strong>Less disk space required</strong>)</p>
<div class="tweetthis" style="text-align:left;"><p> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=Clickodrome%3A+Histoires+de+MMC%E2%80%A6+http%3A%2F%2Fis.gd%2FOerBlK" title="Post to Twitter"><img class="nothumb" src="http://www.ldap389.info/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter-micro3.png" alt="Post to Twitter" /></a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.ldap389.info/2011/06/11/clickodrome-histoires-mmc-gpmc-dnsmgmt-dsa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Powershell: WSUS réaliser un inventaire de conformité</title>
		<link>http://www.ldap389.info/2011/05/22/powershell-wsus-inventaire-client-version-os/</link>
		<comments>http://www.ldap389.info/2011/05/22/powershell-wsus-inventaire-client-version-os/#comments</comments>
		<pubDate>Sun, 22 May 2011 18:21:35 +0000</pubDate>
		<dc:creator>ldap389</dc:creator>
				<category><![CDATA[scripts]]></category>
		<category><![CDATA[sécurité]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[wsus]]></category>

		<guid isPermaLink="false">http://www.ldap389.info/?p=1150</guid>
		<description><![CDATA[Dans cet article nous allons réaliser un inventaire de conformité WSUS des ordinateurs de votre domaine. Les machines qui peuvent recevoir des patchs de sécurité Microsoft doivent avoir une version d&#8217;OS et de Service Pack minimale, ci-dessous un tableau récapitulatif des versions de Windows supportées: Nous allons considérer que le SP1 de Windows Vista n&#8217;est plus [...]]]></description>
			<content:encoded><![CDATA[<p>Dans cet article nous allons réaliser un inventaire de conformité WSUS des ordinateurs de votre domaine. Les machines qui peuvent recevoir des patchs de sécurité Microsoft doivent avoir une version d&#8217;OS et de Service Pack minimale, ci-dessous un tableau récapitulatif des versions de Windows supportées:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2011/05/os-supported2.jpg" rel="lightbox[1150]"><img class="aligncenter size-medium wp-image-1159" title="os-supported" src="http://www.ldap389.info/wp-content/uploads/2011/05/os-supported2-300x75.jpg" alt="" width="300" height="75" /></a></p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2011/05/os-supported.jpg" rel="lightbox[1150]"></a><span id="more-1150"></span>Nous allons considérer que le SP1 de Windows Vista n&#8217;est plus supporté, car le support MS se <a href="http://blogs.technet.com/b/askds/archive/2011/05/18/vista-sp1-end-of-support-reminder.aspx">termine le  12 juillet 2011</a>. Dans un premier temps nous allons donc inventorier avec Powershell les machines qui ne peuvent plus recevoir des patchs de sécurité du fait de leur obsolescence, ceci en s&#8217;inspirant de cet article de <a href="http://blogs.technet.com/b/askds/archive/2010/02/04/inventorying-computers-with-ad-powershell.aspx">AskDS</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$base</span> <span style="color: pink;">=</span> <span style="color: #800000;">'OU=Servers,DC=ldap389,DC=info'</span>
<span style="color: #800080;">$d</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>DateTime<span style="color: #000000;">&#93;</span>::Today.AddDays<span style="color: #000000;">&#40;</span><span style="color: pink;">-</span><span style="color: #804000;">30</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #800080;">$computers</span> <span style="color: pink;">=</span> Get<span style="color: pink;">-</span>ADComputer <span style="color: pink;">-</span><span style="color: #0000FF;">Filter</span> <span style="color: #800000;">'PasswordLastSet -ge $d'</span> <span style="color: pink;">-</span>Searchbase <span style="color: #800080;">$base</span> <span style="color: pink;">-</span>Properties OperatingSystemVersion<span style="color: pink;">,</span>OperatingSystemServicePack<span style="color: pink;">,</span>dNSHostName<span style="color: pink;">,</span>OperatingSystem
&nbsp;
<span style="color: #0000FF;">foreach</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$computer</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$computers</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$computer</span>.OperatingSystemVersion <span style="color: #FF0000;">-lt</span> <span style="color: #800000;">&quot;5.1&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF0000;">-or</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$computer</span>.OperatingSystemVersion <span style="color: #FF0000;">-like</span> <span style="color: #800000;">&quot;5.1*&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF0000;">-and</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$computer</span>.OperatingSystemServicePack <span style="color: #FF0000;">-ne</span> <span style="color: #800000;">&quot;Service Pack 3&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF0000;">-or</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$computer</span>.OperatingSystemVersion <span style="color: #FF0000;">-like</span> <span style="color: #800000;">&quot;5.2*&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF0000;">-and</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$computer</span>.OperatingSystemServicePack <span style="color: #FF0000;">-ne</span> <span style="color: #800000;">&quot;Service Pack 2&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF0000;">-or</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$computer</span>.OperatingSystemVersion <span style="color: #FF0000;">-like</span> <span style="color: #800000;">&quot;6.0*&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF0000;">-and</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$computer</span>.OperatingSystemServicePack <span style="color: #FF0000;">-ne</span> <span style="color: #800000;">&quot;Service Pack 2&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span><span style="color: #800080;">$computer</span>.Name <span style="color: pink;">+</span> <span style="color: #800000;">';'</span> <span style="color: pink;">+</span> <span style="color: #800080;">$computer</span>.OperatingSystem <span style="color: pink;">+</span> <span style="color: #800000;">';'</span> <span style="color: pink;">+</span> <span style="color: #800080;">$computer</span>.OperatingSystemServicePack  <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out<span style="color: #FF0000;">-file</span></span> NOK<span style="color: pink;">-</span>OSVersion.csv <span style="color: #008080; font-style: italic;">-append</span><span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Nous cherchons donc les machines actives, i.e. qui ont renouvelé leur mot de passe avec un DC au cours des 30 derniers jours, situées dans l&#8217;OU <em>&#8220;Servers&#8221;</em> et dont la version d&#8217;OS et de Service Pack n&#8217;est plus supportée par Microsoft. Ces machines listés dans le fichier <em>NOK-OSVersion.csv</em> ne peuvent plus recevoir des mises à jour de sécurité via WSUS, il faudra les mettre à jour.</p>
<p>Nous allons dans un second temps chercher les machines qui sont éligibles à recevoir des mises à jour mais qui ne remontent pas dans votre serveur WSUS. Il existe alors un problème au niveau du client WSUS de la machine où celui ci <a href="http://support.microsoft.com/kb/328010/en-us">n&#8217;est pas configuré</a> et elles téléchargent directement les patchs de sécurité sur Internet, ce qui n&#8217;est pas conseillé dans un environnement d&#8217;entreprise, car vous n&#8217;avez aucun contrôle quant à leur déploiement.</p>
<p>A partir de WSUS 3.0 SP2 il est possible d&#8217;utiliser PowerShell pour gérer vos mises à jour comme nous montre ce tutoriel de <a href="http://boeprox.wordpress.com/2010/10/10/manage-wsus-with-powershell/">Boe Prox</a>, ceci à l&#8217;aide du Namespace <em><a href="http://msdn.microsoft.com/en-us/library/microsoft.updateservices.administration%28v=VS.85%29.aspx">Microsoft.UpdateServices.Administration</a>. </em>Nous allons donc lister toutes les machines contenues dans nos groupes WSUS (sauf le groupe <em>All Computers</em> qui est un groupe qui contient au fait tous les groupes) et les comparer aux ordinateurs issus de notre requête faite sur l&#8217;annuaire Active Directory (<em>$computer</em>):</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$wsusserver</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;WSUS-server&quot;</span>
&nbsp;
<span style="color: #000000;">&#91;</span>void<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>reflection.assembly<span style="color: #000000;">&#93;</span>::<span style="color: #800000;">LoadWithPartialName</span><span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;Microsoft.UpdateServices.Administration&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$wsus</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>Microsoft.UpdateServices.Administration.AdminProxy<span style="color: #000000;">&#93;</span>::getUpdateServer<span style="color: #000000;">&#40;</span><span style="color: #800080;">$wsusserver</span><span style="color: pink;">,</span><span style="color: #800080;">$False</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$groups</span> <span style="color: pink;">=</span> <span style="color: #800080;">$wsus</span>.GetComputerTargetGroups<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">foreach</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$group</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$groups</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$group</span>.Name <span style="color: #FF0000;">-ne</span> <span style="color: #800000;">&quot;All Computers&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
<span style="color: #000000;">&#40;</span><span style="color: #800080;">$wsus</span>.getcomputertargetgroup<span style="color: #000000;">&#40;</span><span style="color: #800080;">$group</span>.Id<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.GetComputerTargets<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|%</span><span style="color: #000000;">&#123;</span><span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000080;">$_</span>.FullDomainName <span style="color: #FF0000;">-eq</span> <span style="color: #800080;">$computer</span>.dNSHostName<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span> ....<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Le FQDN de la machine est la clef commune entre l&#8217;objet ordinateur sous WSUS (attribut <em>FullDomainName</em>) et celui sous Active Directory (attribut <em>DNSHostName</em>). Les objets dont le matching est trouvé seront inscrits dans un fichier <em>$file </em>portant le nom du groupe WSUS auxquels ils appartiennent. Les ordinateurs pour lesquels il n&#8217;y a pas de matching, qui donc ne sont pas remontés sur votre serveur WSUS, sont indiqués dans un fichier <em>NOK-wsus.csv. </em>Pour ces derniers il faudra donc voir si vous les avez configurés pour pointer sur votre serveur WSUS, ou si le <a href="http://www.wsuswiki.com/ClientFAQ">client WSUS a un problème</a>.</p>
<p>Pour télécharger le script complet c&#8217;est ici:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2011/05/check-wsus-clients.ps1"><img class="aligncenter size-full wp-image-83" title="tool" src="http://www.ldap389.info/wp-content/uploads/2010/03/tool1.png" alt="" width="48" height="48" /></a></p>
<p>Il vous faudra modifier les variables suivantes:</p>
<ul>
<li><em>$wsusserver</em>: Nom de votre serveur WSUS.</li>
<li><em>$base</em>: DistingushedName de la base de vôtre recherche sur l&#8217;annuaire AD.</li>
</ul>
<p>&nbsp;</p>
<div class="tweetthis" style="text-align:left;"><p> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=Powershell%3A+WSUS+r%C3%A9aliser+un+inventaire+de+conformit%C3%A9+http%3A%2F%2Fis.gd%2FQ7XG7y" title="Post to Twitter"><img class="nothumb" src="http://www.ldap389.info/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter-micro3.png" alt="Post to Twitter" /></a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.ldap389.info/2011/05/22/powershell-wsus-inventaire-client-version-os/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Powershell: Replication AD</title>
		<link>http://www.ldap389.info/2010/10/08/powershell-replication-active-directory-repadmi/</link>
		<comments>http://www.ldap389.info/2010/10/08/powershell-replication-active-directory-repadmi/#comments</comments>
		<pubDate>Fri, 08 Oct 2010 14:59:05 +0000</pubDate>
		<dc:creator>ldap389</dc:creator>
				<category><![CDATA[scripts]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[repadmin]]></category>

		<guid isPermaLink="false">http://www.ldap389.info/?p=771</guid>
		<description><![CDATA[L&#8217;outil repadmin peut vous servir à surveiller la bonne réplication au sein de votre forêt Active Directory. Vous pouvez lire cet article pour avoir plus de détails, grâce à la commande &#8220;repadmin /replsum&#8221; on peut avoir le statut global de réplication au sein de nôtre forêt. L&#8217;information &#8220;largest delta&#8221; correspond au plus grand intervalle de [...]]]></description>
			<content:encoded><![CDATA[<p>L&#8217;outil repadmin peut vous servir à surveiller la bonne réplication au sein de votre forêt Active Directory. Vous pouvez lire <a href="http://blogs.technet.com/b/askds/archive/2009/07/01/getting-over-replmon.aspx">cet article</a> pour avoir plus de détails, grâce à la commande <strong>&#8220;repadmin /replsum&#8221;</strong> on peut avoir le statut global de réplication au sein de nôtre forêt. L&#8217;information <em>&#8220;largest delta&#8221;</em> correspond au plus grand intervalle de réplication constaté entre le DC indiqué et l&#8217;un de ces partenaires pour l&#8217;ensemble des <a href="http://technet.microsoft.com/en-us/library/cc961591.aspx">partitions AD</a> répliquées par celui ci. Le nombre d&#8217;échecs de réplication pour l&#8217;ensemble des <em>&#8220;Naming Context&#8221;</em> (i.e. partitions AD) et partenaires de réplication nous est aussi donné.</p>
<p>Le but de notre script va être d&#8217;analyser la réplication entrante de chacun de nos DCs grâce à la commande <a href="http://technet.microsoft.com/fr-fr/library/cc835092%28WS.10%29.aspx"><strong>&#8220;repadmin /replsum /bydest&#8221;</strong></a> puis d&#8217;analyser son contenu. Dans le cas où vous avez des RODC dans vôtre infrastructure ils apparaitront dans le résultat de la commande, contrairement au commutateur <strong>/bysrc</strong>, pour plus de détails lire ce <a href="http://www.shariqsheikh.com/blog/index.php/200808/repadmin-results-for-a-rodc/">post</a>. Si pour un DC donné la valeur <em>&#8220;largest delta&#8221; </em>dépasse un seuil à définir ou que des échecs de réplication sont constatés, alors nous analyserons l&#8217;attribut <em><a href="http://msdn.microsoft.com/en-us/library/cc223275%28v=PROT.10%29.aspx">msDS-ReplAllInboundNeighbors </a></em> de l&#8217;objet <em><a href="http://msdn.microsoft.com/en-us/library/ms684291%28VS.85%29.aspx">RootDSE</a></em> de ce contrôleur de domaine. Nous pourrons ainsi avoir le détail du partenaire de réplication qui pose problème et le <em>&#8220;Naming Context&#8221;</em> qui n&#8217;a pas bien répliqué. Il est aussi possible d&#8217;obtenir cette information avec la commande <strong>&#8220;replsum /showrepl %dc_name% /csv</strong>&#8220;, mais l&#8217;information contenue dans l&#8217;attribut <em><a href="http://msdn.microsoft.com/en-us/library/cc223275%28v=PROT.10%29.aspx">msDS-ReplAllInboundNeighbors</a> </em>est au format XML et est donc aussi sympathique à manipuler via script.<br />
<span id="more-771"></span><br />
Il existe déjà sur la toile un script qui fait à peu près la même chose et utilise la commande &#8220;<strong>repadmin.exe /showrepl * /csv&#8221;</strong>, vous pouvez le trouver sur le blog <a href="http://technodrone.blogspot.com/2010/04/monitor-ad-replication-status-with.html">Technodrone</a>, je propose dans ce post une autre méthode et une présentation des résultats différente.</p>
<p>Dans un premier temps nous allons donc analyser les informations renvoyées par notre commande repadmin et parser les résultats à l&#8217;aide des expressions régulières. Voici le résultat d&#8217;une commande <strong>&#8220;repadmin /replsum /bydest&#8221;</strong>.</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2010/10/regex_powershell.jpg" rel="lightbox[771]"><img class="aligncenter size-medium wp-image-775" title="regex_powershell" src="http://www.ldap389.info/wp-content/uploads/2010/10/regex_powershell-300x173.jpg" alt="" width="300" height="173" /></a></p>
<p>Dans le résultat de cette commande seules les valeurs de <em>&#8220;Destination DSA&#8221;</em> (&lt;DC>), <em>&#8220;largest delta&#8221;</em> (&lt;Delta>) et <em>&#8220;fails&#8221;</em> (&lt;fail>) qui est un nombre composé de deux chiffres nous intéresse. L&#8217;expression régulière qui va nous permettre de parser ces valeurs est donc:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #000000;">&#91;</span><span style="color: #008080;">regex</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$regex</span> <span style="color: pink;">=</span> <span style="color: #800000;">'\s+(?&lt;DC&gt;\S+)\s+(?&lt;Delta&gt;\S+)\s+(?&lt;fail&gt;\d{1,2}\s)'</span></pre></div></div>

<p>Dans le cas où un DC est non joignable une erreur nous est renvoyée à la dernière ligne, l&#8217;expression régulière qui va nous permettre de trouver nos données est:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #000000;">&#91;</span><span style="color: #008080;">regex</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$regex2</span> <span style="color: pink;">=</span> <span style="color: #800000;">'\s+(?&lt;FAIL&gt;\d{1,2}\S+)\s\-\s+(?&lt;DC&gt;\S+)'</span></pre></div></div>

<p>Nous reste ensuite à parcourir le résultat de notre commande est utiliser <strong>$matches</strong> pour extraire l&#8217;information désirée. Pour un exemple détaillé de cette méthode vous pouvez lire cet <a href="http://bsonposh.com/archives/595">article</a> qui traite le cas de la commande <strong>&#8220;route print&#8221;</strong> ou bien <a href="http://halr9000.com/article/599">celui ci</a> qui traite la commande <strong>&#8220;netstat&#8221;</strong>.</p>
<p>Le code utilisé pour récupérer nos informations est donc le suivant:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$repadmin</span> <span style="color: pink;">=</span> repadmin <span style="color: pink;">/</span>replsum <span style="color: pink;">/</span>bydest
<span style="color: #800080;">$repadmin</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">ForEach-Object</span> <span style="color: #000000;">&#123;</span>
&nbsp;
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span> <span style="color: #000080;">$_</span> <span style="color: #FF0000;">-match</span> <span style="color: #800080;">$regex</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
<span style="color: #800080;">$process</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;&quot;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select-Object</span> DC<span style="color: pink;">,</span> Delta<span style="color: pink;">,</span> fail
<span style="color: #800080;">$process</span>.dc <span style="color: pink;">=</span> <span style="color: #800080;">$matches</span>.dc
<span style="color: #800080;">$process</span>.Delta <span style="color: pink;">=</span> <span style="color: #800080;">$matches</span>.Delta
<span style="color: #800080;">$process</span>.fail <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$matches</span>.fail<span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$process</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0000FF;">Elseif</span> <span style="color: #000000;">&#40;</span> <span style="color: #000080;">$_</span> <span style="color: #FF0000;">-match</span> <span style="color: #800080;">$regex2</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
<span style="color: #800080;">$process2</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;&quot;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select-Object</span> DC<span style="color: pink;">,</span>fail
<span style="color: #800080;">$process2</span>.fail <span style="color: pink;">=</span> <span style="color: #800080;">$matches</span>.fail
<span style="color: #800080;">$process2</span>.DC <span style="color: pink;">=</span> <span style="color: #800080;">$matches</span>.DC
<span style="color: #800080;">$process2</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Le résultat retourné par <em>&#8220;largest delta&#8221;</em> est au format <em>XXd:XXh:XXm:XXs</em> il nous suffit donc de parser ce résultat et d&#8217;utiliser le cmdlet <strong><a href="http://technet.microsoft.com/en-us/library/ee176916.aspx">New-Timespan</a></strong> pour avoir le résultat en minutes. Si cette valeur excède un seuil en minutes à définir ou que le nombre d&#8217;échecs est supérieur à 0 ($process.fail) alors l&#8217;attribut <em><a href="http://msdn.microsoft.com/en-us/library/cc223275%28v=PROT.10%29.aspx">msDS-ReplAllInboundNeighbors </a></em>du DC concerné est lu.</p>
<p>La méthode utilisée est la même que celle décrite sur le blog <a href="http://blogs.msdn.com/b/adpowershell/archive/2009/11/01/accessing-replication-metadata-using-adpowershell.aspx">Active Directory Powershell</a> pour lire l&#8217;attribut <em><a href="http://msdn.microsoft.com/en-us/library/cc220352%28PROT.13%29.aspx">ms-DS-Repl-AttributeMetaData</a></em> qui est aussi au format XML. Afin de pouvoir lire l&#8217;attribut <a href="http://msdn.microsoft.com/en-us/library/cc223275%28v=PROT.10%29.aspx"><em>msDS-ReplAllInboundNeighbors </em> </a>de l&#8217;objet <em><a href="http://msdn.microsoft.com/en-us/library/ms684291%28VS.85%29.aspx">RootDSE</a></em> sur tous les DCs de votre forêt via Powershell il faut que <a href="http://technet.microsoft.com/en-us/library/dd391908%28WS.10%29.aspx">Active Directory Web Services</a> (inclus dans 2008R2) soit installé sur ceux ci.</p>
<p>Voici donc le resultat obtenu lorsque l&#8217;on lance le script <strong>repl-status.ps1</strong> la valeur <em>$LargestDeltaTreshold</em> exprimée en minutes est égale à 20:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2010/10/replication_status.jpg" rel="lightbox[771]"><img class="aligncenter size-medium wp-image-777" title="replication_status" src="http://www.ldap389.info/wp-content/uploads/2010/10/replication_status-212x300.jpg" alt="" width="212" height="300" /></a></p>
<p>Pour télécharger le script complet c&#8217;est ici:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2010/10/repl-status.ps1"><img class="aligncenter size-full wp-image-83" title="tool" src="http://www.ldap389.info/wp-content/uploads/2010/03/tool1.png" alt="" width="48" height="48" /></a></p>
<div class="tweetthis" style="text-align:left;"><p> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=Powershell%3A+Replication+AD+http%3A%2F%2Fis.gd%2FKUVVTW" title="Post to Twitter"><img class="nothumb" src="http://www.ldap389.info/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter-micro3.png" alt="Post to Twitter" /></a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.ldap389.info/2010/10/08/powershell-replication-active-directory-repadmi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Powershell: Rechercher un paramètre de GPO.</title>
		<link>http://www.ldap389.info/2010/09/08/rechercher-parametre-gpo-powershell-group-policy-module/</link>
		<comments>http://www.ldap389.info/2010/09/08/rechercher-parametre-gpo-powershell-group-policy-module/#comments</comments>
		<pubDate>Wed, 08 Sep 2010 21:53:31 +0000</pubDate>
		<dc:creator>ldap389</dc:creator>
				<category><![CDATA[gpo]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[gpmc]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[regex]]></category>

		<guid isPermaLink="false">http://www.ldap389.info/?p=732</guid>
		<description><![CDATA[Dans cet article nous allons voir comment faire un script qui recherche des paramètres de GPO,  ce point a été abordé par Lindsay Harris dans cet article et celui ci. L&#8217;avantage de sa méthode est que les critères de recherche peuvent être vraiment détaillés, par contre la méthode consiste a exporter toutes les GPOs de votre domaine au [...]]]></description>
			<content:encoded><![CDATA[<p>Dans cet article nous allons voir comment faire un script qui recherche des paramètres de GPO,  ce point a été abordé par Lindsay Harris dans cet <a href="http://blogs.technet.com/b/grouppolicy/archive/2009/04/17/find-settings-in-every-gpo.aspx"></a><a href="http://blogs.technet.com/b/grouppolicy/archive/2009/04/14/tool-images.aspx">article</a> et celui <a href="http://blogs.technet.com/b/grouppolicy/archive/2009/04/17/find-settings-in-every-gpo.aspx">ci</a>. L&#8217;avantage de sa méthode est que les critères de recherche peuvent être vraiment détaillés, par contre la méthode consiste a exporter toutes les GPOs de votre domaine au format XML et effectuer une analyse de ces fichiers, le traitement du script peut donc s&#8217;avérer très long si vous disposez de beaucoup de GPOs. La méthode que je vous propose est plus performante en termes de temps de traitement mais offre des critères de recherche plus limités, à vous de voir celle qui vous convient le mieux.<br />
<span id="more-732"></span><br />
Comme nous l&#8217;indique Florian Frommherz dans ce récent<a href="http://www.frickelsoft.net/blog/?p=265"> post</a> il existe une fonction de recherche de GPO dans la GPMC, vous pouvez d&#8217;ailleurs regarder une <a href="http://edge.technet.com/Media/Group-Policy-Search-with-Lilia/">video de démonstration</a> sur Technet pour plus de détails. La recherche d&#8217;un critère est très rapide mais limitée, car elle se présente sous la forme d&#8217;une liste déroulante. Le but de ce post est de retranscrire cette méthode de recherche avec un script PowerShell, un fois les GPOs filtrées selon notre critère de recherche nous pourrons effectuer des opérations sur celles ci grâce au <a href="http://technet.microsoft.com/en-us/library/ee461027.aspx">Group Policy CmdLets</a>.</p>
<p>Afin de voir quelle requête est lancée par la GPMC lors de la recherche d&#8217;un paramètre de GPO nous allons <a href="http://technet.microsoft.com/en-us/library/cc737379%28WS.10%29.aspx">activer le mode <em>verbose</em></a> de log de la console. Réalisons maintenant une recherche de toutes les GPOs ayant le paramètre &#8220;redirection de dossiers&#8221; de configuré dans la partie utilisateur de la stratégie.</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2010/09/gpo_search.jpg" rel="lightbox[732]"><img class="aligncenter size-medium wp-image-733" title="gpo_search" src="http://www.ldap389.info/wp-content/uploads/2010/09/gpo_search-300x172.jpg" alt="" width="300" height="172" /></a></p>
<p>Puis nous allons consulter le fichier %TEMP%\gpmgmt.log afin de voir quelle opération a été tracée:</p>
<blockquote><p>[VERBOSE] CGPMSearch::DumpCriteria(): Dumping 1 criteria ================<br />
[VERBOSE] CGPMSearch::DumpCriteria(): Property: <span style="color: red;">&#8220;gpoUserExtensions&#8221;</span><br />
[VERBOSE] CGPMSearch::DumpCriteria():    Operation &#8211; <span style="color: red;">Contains</span><br />
[VERBOSE] CGPMSearch::DumpCriteria():     Value (string) &#8220;<span style="color: red;">{25537BA6-77A8-11D2-9B6C-0000F8080861}</span>&#8220;.<br />
[VERBOSE] CGPMSearch::DumpCriteria(): End criteria dump ==================</p></blockquote>
<p>Le filtre de recherche se fait via un simple attribut LDAP de l&#8217;objet de GPO situé dans le container &#8220;<em>CN=System,CN=Policies,DC=%domain%</em>&#8220;. Utilisons <em><a href="http://technet.microsoft.com/en-us/library/cc773354%28WS.10%29.aspx">adsiedit.msc</a></em> afin de voir plus en détails les attributs d&#8217;un objet de stratégie de groupes:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2010/09/ADSI_gpo.jpg" rel="lightbox[732]"><img class="aligncenter size-medium wp-image-734" title="ADSI_gpo" src="http://www.ldap389.info/wp-content/uploads/2010/09/ADSI_gpo-300x240.jpg" alt="" width="300" height="240" /></a></p>
<p>On remarque que l&#8217;attribut <em>gPCUserExtensionNames </em>est de la forme [%GUID1% %GUID2% ....], Le GUID est une valeur fixe qui correspond au type de critère recherché: {25537BA6-77A8-11D2-9B6C-0000F8080861} pour la redirection de dossiers dans la partie utilisateur de la GPO. Une GPO pouvant avoir plusieurs types de paramètres d&#8217;activés, par exemple &#8220;script de logon&#8221; et &#8220;redirection de dossiers&#8221;, les GUIDs sont mis simplement les uns à la suite des autres dans cet attribut.</p>
<p>Pour la partie des paramètres ordinateur de la GPO c&#8217;est le même principe sauf qu&#8217;il s&#8217;agit de l&#8217;attribut <em>gPCMachineExtensionNames</em> de la GPO. Il nous reste donc à inventorier les différents GUID correspondant aux paramètres de GPOs proposés dans la liste déroulante en effectuant une recherche via la GPMC et en analysant le fichier de log. Vu le nombre de paramètres de recherche possibles, 30 pour la configuration utilisateur et 35 pour la configuration ordinateur, les résultats sont disponibles dans ce fichier Excel à télécharger:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2010/09/SearchGPO.xls"><img class="aligncenter size-full wp-image-83" title="tool" src="http://www.ldap389.info/wp-content/uploads/2010/03/tool1.png" alt="" width="48" height="48" /></a></p>
<p>En Powershell il nous suffit de faire une simple recherche avec <a href="http://technet.microsoft.com/en-us/library/ee617198.aspx">Get-ADObject</a> pour rechercher les GPOs contenant une redirection de dossiers, le filtre recherche les objets de type GPO (<em>ObjectClass=GroupPolicyContainer</em>) et ayant l&#8217;attribut<em> gPCUserExtensionNames</em> qui contient le GUID correspondant à la redirection de dossiers:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$ObjGPOs</span> <span style="color: pink;">=</span> Get<span style="color: pink;">-</span>ADObject <span style="color: pink;">-</span><span style="color: #0000FF;">Filter</span> <span style="color: #000000;">&#123;</span><span style="color: #000000;">&#40;</span>ObjectClass <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">&quot;groupPolicyContainer&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF0000;">-and</span> <span style="color: #000000;">&#40;</span>gPCUserExtensionNames <span style="color: #FF0000;">-like</span> <span style="color: pink;">*</span><span style="color: #000000;">&#123;</span>25537BA6<span style="color: pink;">-</span>77A8<span style="color: pink;">-</span>11D2<span style="color: pink;">-</span>9B6C<span style="color: pink;">-</span>0000F8080861<span style="color: #000000;">&#125;</span><span style="color: pink;">*</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#125;</span></pre></div></div>

<p>Si le résultat retourné par <em>$ObjGPOs</em> n&#8217;est pas nul, nous pouvons grâce au CmdLet <a href="http://technet.microsoft.com/en-us/library/ee461057.aspx">Get-GPOReport</a> (ne pas oublier d&#8217;importer le <a href="http://technet.microsoft.com/en-us/library/ee461027.aspx">module Grouppolicy</a>)  exporter le rapport des GPOs trouvées au format HTML, pour cela nous avons besoin d&#8217;entrer en paramètre de la commande (<em>-guid</em>) le <a href="http://support.microsoft.com/kb/216359">GUID de la GPO</a>, mais sans les caractères &#8220;{}&#8221;:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;">Import<span style="color: pink;">-</span>Module GroupPolicy;
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$ObjGPOs</span> <span style="color: #FF0000;">-ne</span> <span style="color: #800080;">$Null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
<span style="color: #0000FF;">foreach</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$ObjGPO</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$ObjGPOs</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>      <span style="color: #800080;">$guid</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>System.Text.RegularExpressions.Regex<span style="color: #000000;">&#93;</span>::Replace<span style="color: #000000;">&#40;</span><span style="color: #800080;">$ObjGPO</span>.Name<span style="color: pink;">,</span><span style="color: #800000;">&quot;[{}]&quot;</span><span style="color: pink;">,</span><span style="color: #800000;">&quot;&quot;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #800080;">$pathtosavef</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;C:\export\&quot;</span> <span style="color: pink;">+</span>  <span style="color: #000000;">&#40;</span>get<span style="color: pink;">-</span>GPO <span style="color: pink;">-</span>guid <span style="color: #800080;">$guid</span><span style="color: #000000;">&#41;</span>.DisplayName <span style="color: pink;">+</span> <span style="color: #800000;">&quot;.html&quot;</span>
    get<span style="color: pink;">-</span>GPOReport <span style="color: pink;">-</span>guid <span style="color: #800080;">$guid</span> <span style="color: pink;">-</span>ReportType html <span style="color: #008080; font-style: italic;">-Path</span> <span style="color: #800080;">$pathtosavef</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>L&#8217;exemple ci dessus exporte les rapports de GPO au format %Nom_GPO%.html dans le dossier <em>c:\export</em>. Nous allons donc faire un script qui demande si nous recherchons un configuration ordinateur ou utilisateur puis le type de paramètre de GPO à chercher, nous lançons donc le script <strong>search_GPO_2008.ps1</strong> avec comme paramètre optionnel <em>-report</em> qui indique le chemin de destination des fichiers html:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2010/09/script_GPO.jpg" rel="lightbox[732]"><img class="aligncenter size-medium wp-image-738" title="script_GPO" src="http://www.ldap389.info/wp-content/uploads/2010/09/script_GPO-300x268.jpg" alt="" width="300" height="268" /></a></p>
<p>Dans l&#8217;exemple ci dessus nous recherchons une GPO ordinateur pour lequel un paramètre de service est configuré à travers les <a href="http://www.grouppolicy.biz/2010/03/what-are-group-policy-preferences/">préférences de stratégie de groupe</a> , nous indiquons donc <strong>2</strong> puis <strong>20</strong>. Si vous n&#8217;indiquez pas de paramètre <em>-report</em>, aucun rapport html n&#8217;est généré mais les informations sur le nom de la GPO, son GUID et sa date de création sont tout de même affichés.Pour télécharger le script c&#8217;est ici:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2010/09/search_GPO_2008.ps1"><img class="aligncenter size-full wp-image-83" title="tool" src="http://www.ldap389.info/wp-content/uploads/2010/03/tool1.png" alt="" width="48" height="48" /></a><br />
Pour ceux qui ne sont pas encore sous Active Directory 2008, voici un script équivalent pour la version 2003, réalisé à l&#8217;aide des <a href="http://www.quest.com/powershell/activeroles-server.aspx">Quest AD Cmdlets</a>, la fonction d&#8217;export au format HTML n&#8217;est pas disponible car il n&#8217;y a pas (à ce jour), de CmdLets pouvant réaliser cette opération. Ci dessous le lien pour télécharger <strong>search_GPO_2003.ps1</strong>:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2010/09/search_GPO_2003.ps1"><img class="aligncenter size-full wp-image-83" title="tool" src="http://www.ldap389.info/wp-content/uploads/2010/03/tool1.png" alt="" width="48" height="48" /></a></p>
<p>Le principe de fonctionnement est le même:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2010/09/gpo_search_quest.jpg" rel="lightbox[732]"><img class="aligncenter size-medium wp-image-739" title="gpo_search_quest" src="http://www.ldap389.info/wp-content/uploads/2010/09/gpo_search_quest-300x201.jpg" alt="" width="300" height="201" /></a></p>
<p>Vous pouvez adapter le script <strong>search_GPO_2008.ps1 </strong>afin de faire d&#8217;autres types de manipulations sur les GPOs issues de vôtre filtre de recherche, par exemple les sauvegarder dans un dossier particulier avec le CmdLet <a href="http://technet.microsoft.com/en-us/library/ee461052.aspx">Backup-GPO</a> etc&#8230;</p>
<div class="tweetthis" style="text-align:left;"><p> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=Powershell%3A+Rechercher+un+param%C3%A8tre+de+GPO.+http%3A%2F%2Fis.gd%2F1HzTDM" title="Post to Twitter"><img class="nothumb" src="http://www.ldap389.info/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter-micro3.png" alt="Post to Twitter" /></a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.ldap389.info/2010/09/08/rechercher-parametre-gpo-powershell-group-policy-module/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Surveiller l&#8217;application des liens de GPOs: GPLink</title>
		<link>http://www.ldap389.info/2010/04/01/monitorer-lien-gpo-gplink/</link>
		<comments>http://www.ldap389.info/2010/04/01/monitorer-lien-gpo-gplink/#comments</comments>
		<pubDate>Thu, 01 Apr 2010 11:59:11 +0000</pubDate>
		<dc:creator>ldap389</dc:creator>
				<category><![CDATA[gpo]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[gplink]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[vbs]]></category>

		<guid isPermaLink="false">http://www.ldap389.info/?p=350</guid>
		<description><![CDATA[Nous pouvons en analysant le journal de sécurité de chaque DC surveiller les changements de liens d&#8217;objets de stratégie de groupe. L&#8217;attribut à auditer est GPLink, de cette manière nous pourrons savoir comment les GPOs sont appliquées sur notre domaine. Pour pouvoir enregistrer les modifications dans le journal de sécurité de chaque DC vous devez [...]]]></description>
			<content:encoded><![CDATA[<p>Nous pouvons en analysant le journal de sécurité de chaque DC surveiller les changements de liens d&#8217;objets de stratégie de groupe. L&#8217;attribut à auditer est <a href="http://msdn.microsoft.com/en-us/library/cc232505(PROT.13).aspx">GPLink</a>, de cette manière nous pourrons savoir comment les GPOs sont appliquées sur notre domaine.</p>
<p>Pour pouvoir enregistrer les modifications dans le journal de sécurité de chaque DC vous devez opter pour des solutions payantes type Snare et/ou Kiwi, ou bien mettre en place un système maison pour effectuer de la <a href="http://blogs.technet.com/otto/archive/2008/07/08/quick-and-dirty-enterprise-eventing-for-windows.aspx">surveillance de journaux d&#8217;événements</a> sur plusieurs DCs en utilisant la redirection de ceux ci sous 2008, vous pouvez aussi voir si on peut surveiller ce journal de sécurité par un <a href="http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/logs/eventlogs/#AsyncEventLog.htm">script</a>, mais cela risque de trop solliciter votre DC.<br />
<span id="more-350"></span><br />
Comme nous l&#8217;avons vu dans le post précédent l&#8217;attribut GPLink est audité <a href="http://technet.microsoft.com/en-us/library/cc773209(WS.10).aspx">par défaut</a>. Nous allons voir la structure de cet attribut de chaque OU/Site/Domaine avec <a href="http://technet.microsoft.com/en-us/library/cc773354(WS.10).aspx">adsiedit.msc</a>:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2010/03/adsiedit1.jpeg" rel="lightbox" title="adsiedit"><img class="aligncenter size-medium wp-image-353" title="adsiedit" src="http://www.ldap389.info/wp-content/uploads/2010/03/adsiedit1-300x262.jpg" alt="" width="300" height="262" /></a></p>
<p>Il se présente de la forme <em>[LDAP://CN={31F5F311-013D-11D2-125F-00D04F0E84F9},CN=Policies,CN=System,DC=ldap389,DC=info;0][LDAP://CN={31F5F311-0187-EFD2-345F-BED04F1284F9},CN=Policies,CN=System,DC=ldap389,DC=info;2]</em>, chaque GPO liée à l&#8217;objet est séparée des <em>&#8220;[]&#8220;</em>, chaque valeur possède deux parties: Le Distinguished Name de la GPO et comment celle ci est appliquée et liée à notre objet, se sont les chiffres de 0 à 3 indiqués après le <em>&#8220;;&#8221;</em>:</p>
<ul>
<li>0: GPO avec lien activé, pas de mode appliqué (enforced)</li>
<li>1: GPO avec lien désactivé, pas de mode appliqué (enforced)</li>
<li>2: GPO avec lien activé, mode appliqué (enforced)</li>
<li>3: GPO avec lien désactivé, mode appliqué (enforced)</li>
</ul>
<p>Vous pouvez lire toutes ces informations par script avec des requêtes LDAP comme montré sur <a href="http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/usersgroups/ous/#ReturnGPOInfo.htm">cette page</a>. Il nous faut maintenant lire dans le journal de sécurité de chaque DC les modifications de cet attribut GPLink:</p>
<p>Sous Windows 2003 vous n&#8217;êtes que notifié d&#8217;un changement de valeur de cet attribut, vous n&#8217;avez pas la valeur avant/après indiquée dans le journal de sécurité. L&#8217;ID <a href="http://www.eventid.net/display.asp?eventid=566&#038;eventno=4015&#038;source=Security&#038;phase=1">566</a> est généré dans le journal d&#8217;événements:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2010/03/gpling2003.jpg" rel="lightbox" title="gplink-security-envent-2003"><img class="aligncenter size-medium wp-image-354" title="gplink2003" src="http://www.ldap389.info/wp-content/uploads/2010/03/gpling2003-257x300.jpg" alt="" width="257" height="300" /></a>,</p>
<p>Nous n&#8217;avons donc d&#8217;indiqué que l&#8217;attribut GPLink a été modifié, le nom du compte ayant effectué la modification, sur quel DC,  et le Distinguished Name de votre OU/Site/Domaine. A partir de cette dernière information, pour lire la nouvelle valeur il vous faut juste faire une requête LDAP sur le DC sur lequel la valeur a été modifiée. Pour lire l&#8217;ancienne valeur, il vous faut un site de LAG, ce type de DC à réplication retardée n&#8217;est pas supporté par Microsoft si l&#8217;on s&#8217;en sert dans le <a href="http://technet.microsoft.com/en-us/library/dd835581(WS.10).aspx">cadre d&#8217;un PRA</a>, mais rien ne nous empêche de nous en servir afin de faire une requête LDAP qui nous donnera la valeur avant modification du GPLink. Restera ensuite à comparer la nouvelle valeur (prise sur le DC sur lequel la modification a eu lieu) à l&#8217;ancienne valeur (obtenue à partir du site de lag).</p>
<p>Sous Windows 2008 vous n&#8217;avez pas besoin de site de lag, nous pouvons directement à partir du journal de sécurité d&#8217;un DC avoir la valeur &#8220;avant&#8221; et &#8220;après&#8221; du GPLink. Pour cela il vous suffit d&#8217;activer <a href="http://technet.microsoft.com/en-us/library/cc731607(WS.10).aspx">l&#8217;audit AD</a> sur vos DCs. Si nous filtrons le journal de sécurité sur l&#8217;ID <a href="http://www.eventid.net/display.asp?eventid=5136&amp;eventno=10591&amp;source=Microsoft-Windows-Security-Auditing&amp;phase=1">5136</a>, nous pouvons avoir l&#8217;ancienne valeur (event de suppression de GPLink) et la nouvelle valeur (event de création de GPLink)</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2010/03/gplinlenevt2008.jpg" rel="lightbox" title="gplink-security-envent-5136"><img class="aligncenter size-medium wp-image-356" title="gplink-security-envent-5136" src="http://www.ldap389.info/wp-content/uploads/2010/03/gplinlenevt2008-300x133.jpg" alt="" width="300" height="133" /></a></p>
<p>Si vous liez votre première GPO sur un objet alors la valeur avant sera nulle et la valeur après égale au nouveau GPLink. Inversement si vous supprimez le dernier lien sur un objet alors la valeur avant sera le GPLink et la valeur après sera nulle.  Afin de gérer ce cas de figure sous 2003 c&#8217;est un peu plus complexe: Il faudra gérer les codes d&#8217;erreur de la requête LDAP, si vous créez le premier lien de GPO sur une OU, la requête LDAP pour obtenir la valeur de GPLink sur le DC sur lequel a été créé le lien fonctionnera, si vous interrogez la même valeur sur le DC de lag elle est à <em>&lt;not set&gt;</em>, donc la requête LDAP sortira en erreur, il faudra donc gérer ces différents cas de figure.</p>
<p>Vous devez donc selon la version d&#8217;OS de votre DC <a href="http://www.intersectalliance.com/resources/Documentation/Guide_to_Snare_for_Windows-2.8.pdf">paramétrer l&#8217;agent SNARE</a> pour enregistrer les événements 566 ou 5136 de votre journal de sécurité, vous pouvez bien entendu utiliser d&#8217;autres outils. Comme serveur collectant les informations nous utilisons Kiwi. A ce propos nous avons constaté que certaines valeurs ne remontaient pas avec un <em>friendly name</em>, c&#8217;était le cas pour le <em>Distinguished Name</em> de l&#8217;objet (OU,Site,domaine) sur lequel le GPLink était modifié, le nom remonté était son GUID au format chaine de caractère, afin de pouvoir retrouver l&#8217;objet utilisez cette <a href="http://support.microsoft.com/kb/325648">fonction de conversion</a> fournie par MS. On a noté d&#8217;ailleurs une erreur dans cette KB sur le nom de la fonction, l&#8217;avant dernière ligne est à remplacer par <em>&#8220;ConvertStringGUIDToHexStringGUID = octetStr&#8221;.</em></p>
<p>Nous allons maintenant voir comment comparer les valeurs &#8220;avant/après&#8221; de GPLink afin de connaître les modifications de liens de GPOs.  Comme déjà expliqué le lien d&#8217;une GPO sur une OU/Site/Domaine comporte deux parties, le DN de la GPO et une valeur indiquant l&#8217;état du lien. Voici donc les différents cas de figure possible.</p>
<ul>
<li>GPLink avant [DNGPO1;0][DNGPO2;3] et GPLink après [DNGPO1;0][DNGPO2;3][DNGPO3;2] alors un nouveau lien activé et appliqué vient d&#8217;être créé.</li>
<li>GPLink avant [DNGPO1;0][DNGPO2;3] et GPLink après [DNGPO1;0] alors le lien de la GPO DNGPO2 vient d&#8217;être effacé sur notre OU/Site/Domaine.</li>
<li>GPLink avant [DNGPO1;0][DNGPO2;3] et GPLink après [DNGPO1;1][DNGPO2;3] alors le lien de la GPO DNGPO1 a été désactivé (mais pas supprimé).</li>
<li>GPLink avant [DNGPO1;0][DNGPO2;3] et GPLink après [DNGPO1;0][DNGPO2;2] alors le lien de la GPO DNGPO2 a été activé et est toujours appliqué.</li>
<li>etc&#8230;</li>
</ul>
<p>Nous allons pour effectuer nos comparaisons utiliser les <a href="http://technet.microsoft.com/en-us/library/ee176993.aspx"><em>dictionnary objects.</em></a> Nous aurons donc deux dictionnaires à comparer, un avec les GPLinks avant et l&#8217;autre après. Les clefs de chaque dictionnaire seront les <em>Distinguished Name</em> de GPOs et les valeurs les chiffres de 0 à 3 indiquant le statut du lien de GPO. Voici comment créer vos deux dictionnaires:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #008000;">'After modification GPLink dicitonnary
</span><span style="color: #151B8D; font-weight: bold;">Set</span> GPLinkdict = <span style="color: #E56717; font-weight: bold;">CreateObject</span>(<span style="color: #800000;">&quot;Scripting.Dictionary&quot;</span>)
<span style="color: #008000;">'Before modification GPLink dicitonnary
</span><span style="color: #151B8D; font-weight: bold;">Set</span> GPLinkdictLAG = <span style="color: #E56717; font-weight: bold;">CreateObject</span>(<span style="color: #800000;">&quot;Scripting.Dictionary&quot;</span>)
&nbsp;
<span style="color: #008000;">'strGPLinkAfter is the GPLink value after modification, you retrieved it with the event log
</span><span style="color: #008000;">'under Windows 2008 and with an LDAP request on the where DC the modification occurred under Windows 2003
</span>
<span style="color: #8D38C9; font-weight: bold;">if</span> instr(strGPLinkAfter,<span style="color: #800000;">&quot;]&quot;</span>) &lt;&gt; 0 <span style="color: #8D38C9; font-weight: bold;">then</span>
OUModifiedGPLINK = split(strGPLinkAfter,<span style="color: #800000;">&quot;]&quot;</span>)
<span style="color: #8D38C9; font-weight: bold;">For</span> i = <span style="color: #151B8D; font-weight: bold;">UBound</span>(OUModifiedGPLINK) -1 <span style="color: #8D38C9; font-weight: bold;">to</span> <span style="color: #151B8D; font-weight: bold;">LBound</span>(OUModifiedGPLINK) <span style="color: #8D38C9; font-weight: bold;">Step</span> -1
GPOLinkstatus = split(OUModifiedGPLINK(i),<span style="color: #800000;">&quot;;&quot;</span>)
GPLinkdict.add GPOLinkstatus(0),GPOLinkstatus(1)
<span style="color: #8D38C9; font-weight: bold;">Next</span>
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">if</span>
&nbsp;
&nbsp;
<span style="color: #008000;">'strGPLinkBefore is the GPLink value before modification, you retrieved it with the event log
</span><span style="color: #008000;">'under Windows 2008 and with an LDAP request on the LAG DC under Windows 2003
</span>
&nbsp;
<span style="color: #8D38C9; font-weight: bold;">if</span> instr(strGPLinkBefore,<span style="color: #800000;">&quot;]&quot;</span>) &lt;&gt; 0 <span style="color: #8D38C9; font-weight: bold;">then</span>
OUModifiedGPLINKLAG = split(strGPLinkBefore,<span style="color: #800000;">&quot;]&quot;</span>)
<span style="color: #8D38C9; font-weight: bold;">For</span> j = <span style="color: #151B8D; font-weight: bold;">UBound</span>(OUModifiedGPLINKLAG)-1 <span style="color: #8D38C9; font-weight: bold;">to</span> <span style="color: #151B8D; font-weight: bold;">LBound</span>(OUModifiedGPLINKLAG) <span style="color: #8D38C9; font-weight: bold;">Step</span> -1
GPOLinkstatusLAG = split(OUModifiedGPLINKLAG(j),<span style="color: #800000;">&quot;;&quot;</span>)
GPLinkdictLAG.add GPOLinkstatusLAG(0),GPOLinkstatusLAG(1)
<span style="color: #8D38C9; font-weight: bold;">Next</span>
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">if</span></pre></div></div>

<p>Pour télécharger l&#8217;exemple de code c&#8217;est ici:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2010/07/GPLINK0.txt"><img class="aligncenter size-full wp-image-83" title="tool" src="http://www.ldap389.info/wp-content/uploads/2010/03/tool1.png" alt="" width="48" height="48" /></a></p>
<p>Maintenant nous allons parcourir le dictionnaire GPLinkdict contenant les clefs et valeurs après modification et les comparer aux clefs et valeurs de l&#8217;autre dictionnaire. Si nous voyons qu&#8217;une des clefs parcourue n&#8217;existe pas dans le dictionnaire GPLinkdictLAG (avant modification) alors un lien de GPO vient d&#8217;être créé. Si pour une clef identique la valeur a changé alors l&#8217;état du lien de GPO à changé, si l&#8217;on passe de 0 ou 2 à 1 ou 3 alors la GPO a été désactivée. Avec ce script nous allons pouvoir avoir la création de nouveau lien de GPO et la modification d&#8217;état d&#8217;un lien:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">&nbsp;
<span style="color: #008000;">'The DC where the modification was recorded, retrieved with eventlog
</span>dcsource = <span style="color: #800000;">&quot;DCSOURCENAME&quot;</span>
&nbsp;
<span style="color: #008000;">'OU/Site/Domain name where GPO Link was modified, retrieved with eventlog
</span>OUName = <span style="color: #800000;">&quot;OUName&quot;</span>
&nbsp;
<span style="color: #008000;">'User who made the modication, retrieved with eventlog
</span>Username = <span style="color: #800000;">&quot;UsernName&quot;</span>
&nbsp;
<span style="color: #8D38C9; font-weight: bold;">For</span> <span style="color: #8D38C9; font-weight: bold;">Each</span> oGPLinkdict <span style="color: #8D38C9; font-weight: bold;">in</span> GPLinkdict
	<span style="color: #8D38C9; font-weight: bold;">If</span> <span style="color: #8D38C9; font-weight: bold;">Not</span> GPLinkdictLAG.Exists(oGPLinkdict) <span style="color: #8D38C9; font-weight: bold;">Then</span>
&nbsp;
	<span style="color: #151B8D; font-weight: bold;">Set</span> objGPOd = <span style="color: #E56717; font-weight: bold;">GetObject</span>(split(replace(oGPLinkdict,<span style="color: #800000;">&quot;LDAP://&quot;</span>,<span style="color: #800000;">&quot;LDAP://&quot;</span>&amp;dcsource&amp;<span style="color: #800000;">&quot;/&quot;</span>),<span style="color: #800000;">&quot;[&quot;</span>)(1))
	DNobjGPOd = objGPOd.<span style="color: #151B8D; font-weight: bold;">Get</span>(<span style="color: #800000;">&quot;DisplayName&quot;</span>)
	Msgbox Username&amp;<span style="color: #800000;">&quot; created a link on this object: &quot;</span>&amp; OUName &amp;<span style="color: #800000;">&quot;  / GPOName: &quot;</span>&amp;DNobjGPOd &amp; <span style="color: #800000;">&quot;  / Link Value: &quot;</span>&amp;GPLinkdict.Item(oGPLinkdict)
&nbsp;
	<span style="color: #8D38C9; font-weight: bold;">Else</span> 
		<span style="color: #8D38C9; font-weight: bold;">If</span> GPLinkdictLAG.Item(oGPLinkdict) &lt;&gt; GPLinkdict.Item(oGPLinkdict) <span style="color: #8D38C9; font-weight: bold;">then</span>
&nbsp;
			<span style="color: #8D38C9; font-weight: bold;">if</span> (GPLinkdictLAG.Item(oGPLinkdict) = 0 <span style="color: #8D38C9; font-weight: bold;">OR</span> GPLinkdictLAG.Item(oGPLinkdict) = 2) <span style="color: #8D38C9; font-weight: bold;">AND</span> (GPLinkdict.Item(oGPLinkdict) =1 <span style="color: #8D38C9; font-weight: bold;">OR</span> GPLinkdict.Item(oGPLinkdict) = 3) <span style="color: #8D38C9; font-weight: bold;">then</span>
&nbsp;
			<span style="color: #151B8D; font-weight: bold;">Set</span> objGPOd = <span style="color: #E56717; font-weight: bold;">GetObject</span>(split(replace(oGPLinkdict,<span style="color: #800000;">&quot;LDAP://&quot;</span>,<span style="color: #800000;">&quot;LDAP://&quot;</span>&amp;dcsource&amp;<span style="color: #800000;">&quot;/&quot;</span>),<span style="color: #800000;">&quot;[&quot;</span>)(1))
			DNobjGPOd = objGPOd.<span style="color: #151B8D; font-weight: bold;">Get</span>(<span style="color: #800000;">&quot;DisplayName&quot;</span>)
			Msgbox Username&amp;<span style="color: #800000;">&quot; disabled a link on this object: &quot;</span>&amp; OUName &amp;<span style="color: #800000;">&quot;  / GPOName: &quot;</span>&amp;DNobjGPOd &amp; <span style="color: #800000;">&quot;  / Link Value Before: &quot;</span>&amp;GPLinkdictLAG.Item(oGPLinkdict)&amp;<span style="color: #800000;">&quot;  / Link Value After: &quot;</span>&amp;GPLinkdict.Item(oGPLinkdict)
&nbsp;
			<span style="color: #8D38C9; font-weight: bold;">Else</span>
&nbsp;
			<span style="color: #151B8D; font-weight: bold;">Set</span> objGPOd = <span style="color: #E56717; font-weight: bold;">GetObject</span>(split(replace(oGPLinkdict,<span style="color: #800000;">&quot;LDAP://&quot;</span>,<span style="color: #800000;">&quot;LDAP://&quot;</span>&amp;dcsource&amp;<span style="color: #800000;">&quot;/&quot;</span>),<span style="color: #800000;">&quot;[&quot;</span>)(1))
			DNobjGPOd = objGPOd.<span style="color: #151B8D; font-weight: bold;">Get</span>(<span style="color: #800000;">&quot;DisplayName&quot;</span>)
			Msgbox Username&amp;<span style="color: #800000;">&quot; enabled a link on this object: &quot;</span>&amp; OUName &amp;<span style="color: #800000;">&quot;  / GPOName: &quot;</span>&amp;DNobjGPOd &amp; <span style="color: #800000;">&quot;  / Link Value Before: &quot;</span>&amp;GPLinkdictLAG.Item(oGPLinkdict)&amp;<span style="color: #800000;">&quot;  / Link Value After: &quot;</span>&amp;GPLinkdict.Item(oGPLinkdict)
&nbsp;
			<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">if</span>
&nbsp;
&nbsp;
		<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">if</span> 
	<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">if</span>
<span style="color: #8D38C9; font-weight: bold;">Next</span></pre></div></div>

<p>Pour télécharger l&#8217;exemple de code c&#8217;est ici:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2010/07/GPLINK1.txt"><img class="aligncenter size-full wp-image-83" title="tool" src="http://www.ldap389.info/wp-content/uploads/2010/03/tool1.png" alt="" width="48" height="48" /></a></p>
<p>Maintenant il ne nous reste plus qu&#8217;à identifier les liens de GPOs supprimés, pour cela nous allons parcourir le dictionnaire GPLinkdictLAG qui contient les valeurs avant modification et voir si une clef n&#8217;existe pas dans le dictionnaire GPLinkdict, si c&#8217;est le cas alors un lien de GPO a été supprimé.</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #008000;">'Enter LAGDC if you have one, it will be usefull only in this case : if a Link is deleted and the GPO is deleted from the domain as well in the same time
</span><span style="color: #008000;">'In that case we can not retrieve GPO Display Name if we do not have lag site.
</span><span style="color: #008000;">'If no lag site then LAGDC = &quot;&quot;
</span>LAGDC = <span style="color: #800000;">&quot;LAGDCNAME&quot;</span>
&nbsp;
<span style="color: #8D38C9; font-weight: bold;">For</span> <span style="color: #8D38C9; font-weight: bold;">Each</span> oGPLinkdictLAG <span style="color: #8D38C9; font-weight: bold;">in</span> GPLinkdictLAG
  <span style="color: #8D38C9; font-weight: bold;">If</span> <span style="color: #8D38C9; font-weight: bold;">Not</span> GPLinkdict.Exists(oGPLinkdictLAG) <span style="color: #8D38C9; font-weight: bold;">Then</span>
	err.clear
	<span style="color: #151B8D; font-weight: bold;">Set</span> objGPOd = <span style="color: #E56717; font-weight: bold;">GetObject</span>(split(replace(oGPLinkdictLAG,<span style="color: #800000;">&quot;LDAP://&quot;</span>,<span style="color: #800000;">&quot;LDAP://&quot;</span>&amp;dcsource&amp;<span style="color: #800000;">&quot;/&quot;</span>),<span style="color: #800000;">&quot;[&quot;</span>)(1))
	<span style="color: #8D38C9; font-weight: bold;">if</span> err.number &lt;&gt; 0 <span style="color: #8D38C9; font-weight: bold;">then</span>
		<span style="color: #8D38C9; font-weight: bold;">if</span> LAGDC &lt;&gt; <span style="color: #800000;">&quot;&quot;</span> <span style="color: #8D38C9; font-weight: bold;">then</span>
		<span style="color: #151B8D; font-weight: bold;">Set</span> objGPOd = <span style="color: #E56717; font-weight: bold;">GetObject</span>(split(replace(oGPLinkdict,<span style="color: #800000;">&quot;LDAP://&quot;</span>,<span style="color: #800000;">&quot;LDAP://&quot;</span>&amp;dcsource&amp;<span style="color: #800000;">&quot;/&quot;</span>),<span style="color: #800000;">&quot;[&quot;</span>)(1))
		DNobjGPOd = objGPOd.<span style="color: #151B8D; font-weight: bold;">Get</span>(<span style="color: #800000;">&quot;DisplayName&quot;</span>)
		<span style="color: #8D38C9; font-weight: bold;">Else</span>
		DNobjGPOd = split(oGPLinkdictLAG,<span style="color: #800000;">&quot;[&quot;</span>)(1)
	<span style="color: #8D38C9; font-weight: bold;">Else</span> 
	DNobjGPOd = objGPOd.<span style="color: #151B8D; font-weight: bold;">Get</span>(<span style="color: #800000;">&quot;DisplayName&quot;</span>)
	<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">if</span>
	Msgbox Username&amp;<span style="color: #800000;">&quot; deleted a link on this object: &quot;</span>&amp; OUName &amp;<span style="color: #800000;">&quot;  / GPOName: &quot;</span>&amp;DNobjGPOd &amp; <span style="color: #800000;">&quot;  / Link Value was: &quot;</span>&amp;GPLinkdictLAG.Item(oGPLinkdict)
  <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">if</span>
<span style="color: #8D38C9; font-weight: bold;">Next</span></pre></div></div>

<p>Pour télécharger l&#8217;exemple de code c&#8217;est ici:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2010/07/GPLINK2.txt"><img class="aligncenter size-full wp-image-83" title="tool" src="http://www.ldap389.info/wp-content/uploads/2010/03/tool1.png" alt="" width="48" height="48" /></a></p>
<p>Avec ce post et le <a href="/?p=276">précédent</a> vous pouvez maintenant construire un outil de surveillance des modifications de GPOs sur votre domaine. Vous pouvez, en plus de générer des rapports, lancer une sauvegarde de la GPO modifié via les scripts fournis avec <a href="http://technet.microsoft.com/en-us/library/cc776655%28WS.10%29.aspx">GPMC</a>.</p>
<div class="tweetthis" style="text-align:left;"><p> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=Surveiller+l%E2%80%99application+des+liens+de+GPOs%3A+GPLink+http%3A%2F%2Fis.gd%2FonG6k6" title="Post to Twitter"><img class="nothumb" src="http://www.ldap389.info/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter-micro3.png" alt="Post to Twitter" /></a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.ldap389.info/2010/04/01/monitorer-lien-gpo-gplink/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Surveiller les changements des GPOs : Monitorer le SYSVOL</title>
		<link>http://www.ldap389.info/2010/03/26/surveiller-changement-gpo-sysvol/</link>
		<comments>http://www.ldap389.info/2010/03/26/surveiller-changement-gpo-sysvol/#comments</comments>
		<pubDate>Fri, 26 Mar 2010 22:43:10 +0000</pubDate>
		<dc:creator>ldap389</dc:creator>
				<category><![CDATA[gpo]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[sysvol]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[wmi]]></category>

		<guid isPermaLink="false">http://www.ldap389.info/?p=276</guid>
		<description><![CDATA[Nous allons dans ce post expliquer comment monitorer les changements sur les GPOs de votre domaine en contrôllant le GPT. Seuls les effacements, modifications de la configuration ordinateur/utilisateur, créations de GPOs sont surveillés. A propos du monitoring d&#8217;objets de stratégie de groupe via le journal d&#8217;événements vous pouvez lire cet article. Les méthodes utilisées dans [...]]]></description>
			<content:encoded><![CDATA[<p>Nous allons dans ce post expliquer comment monitorer les changements sur les GPOs de votre domaine en contrôllant le <a href="http://www.gpoguy.com/FAQs/Whitepapers/tabid/63/articleType/ArticleView/articleId/6/Understanding-Group-Policy-Storage.aspx">GPT</a>. Seuls les effacements, modifications de la configuration ordinateur/utilisateur, créations de GPOs sont surveillés. A propos du monitoring d&#8217;objets de stratégie de groupe via le journal d&#8217;événements vous pouvez lire cet <a href="http://blogs.msdn.com/ericfitz/archive/2005/08/04/447951.aspx">article</a>. Les méthodes utilisées dans le lien précédent indiquent, entre autres, comment activer un audit sur le partage <em>\\domainname\sysvol\domainfqdn\Policies</em> et remonter via le journal de sécurité de chaque DC les changements intervenus sur la partie GPT d&#8217;une GPO. Nous allons décrire une autre méthode pour enregistrer les modifications de vos GPOs dans votre domaine.<br />
<span id="more-276"></span><br />
Lors de la réplication d&#8217;objets GPO dans votre domaine la partie GPT est répliquée via la les systèmes <a href="http://technet.microsoft.com/en-us/library/cc773238(WS.10).aspx">DFS-R</a> sous Windows 2008 et <a href="http://support.microsoft.com/kb/220140">FRS</a> sous Windows 2003 (pour migrer c&#8217;est <a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&#038;FamilyID=df8e5e84-c6c6-4cef-9dab-304c92299804#tm">ici</a>.) Le même répertoire partagé, le <a href="http://technet.microsoft.com/en-us/library/cc778037(WS.10).aspx">SYSVOL</a>, est modifié lors d&#8217;une création/suppression/changement de paramètre d&#8217;une GPO. Nous pouvons donc enregistrer sur un seul DC les modifications effectuées par vos administrateurs.</p>
<p>Lors de la création/suppression d&#8217;une GPO dans votre domaine le dossier <em>\\domainname\sysvol\domainfqdn\Policies\{%GPO_GUID%}</em> est créé ou effacé. Lors de la modification des paramètres ordinateur/utilisateur le fichier <em>\\domainname\sysvol\domainfqdn\Policies\{%GPO_GUID%}\gpt.ini</em> est modifié comme l&#8217;indique ce <a href="http://blogs.technet.com/grouppolicy/archive/2007/12/14/understanding-the-gpo-version-number.aspx">post</a>. Le but de notre script est donc de notifier en presque temps réel les modifications sur ce dossier et fichier sur un DC.</p>
<p>Quels sont les avantages/inconvénients par rapport à la méthode de notification via le <a href="http://blogs.msdn.com/ericfitz/archive/2005/08/04/447951.aspx">journal de sécurité</a>?</p>
<ul>
<li><strong>Inconvénients:</strong> Un seul DC est sollicité, une charge CPU/Mémoire est à prévoir pour ce serveur, de plus<a href="http://blog.scottlowe.org/2007/07/20/delayed-replication-dcs-and-authoritative-restores/"> un site de LAG</a> est à prévoir pour obtenir des informations sur la suppression de GPOs sous Windows 2003. Nous n&#8217;avons pas le nom de compte de la personne ayant effectué la modification. Nous sommes notifiés une fois la réplication du SYSVOL survenue sur le DC sur lequel tourne le script, nous n&#8217;avons donc pas une remontée des événements en temps réel qui sont enregistrés dans le journal de sécurité de chaque DC via l&#8217;audit de fichiers.</li>
<li><strong>Avantages:</strong> Afin d&#8217;avoir un enregistrement en temps réel des événements du journal de sécurité de chaque DC un logiciel payant de Syslog est necessaire (<a href="http://www.kiwisyslog.com/kb/how-to:-receive-windows-event-log-information/">Kiwi</a> et <a href="http://www.intersectalliance.com/projects/SnareWindows/">Snare</a> par ex), ma méthode est gratuite. Un seul DC est sollicité et vous n&#8217;avez pas besoin d&#8217;activer l&#8217;audit du système de fichiers sur le SYSVOL de tous les DCs et d&#8217;y installer l&#8217;agent Snare, ce qui limite la charge CPU/Mémoire de l&#8217;ensemble des DCs.</li>
</ul>
<p>Le but de cet article est de montrer comment installer sur un seul DC de votre domaine un service (script) qui détecte les changements de GPOs. Pour réaliser ce script nous allons utiliser <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=2cc30a64-ea15-4661-8da4-55bbc145c30e&#038;displaylang=en">WMI code creator</a> pour monitorer les créations/effacements de dossiers <em>{%GPO_GUID%}</em> et modifications des fichiers <em>{%GPO_GUID%}gpt.ini </em>sur le SYSVOL.</p>
<p>Voici comment générer le script pour surveiller la création d&#8217;un dossier  <em>{%GPO_GUID%}:</em></p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2010/03/wmi1.jpg" rel=”lightbox” title="wmi code creator" rel="lightbox[276]"><img class="aligncenter size-medium wp-image-282" title="wmi code creator" src="http://www.ldap389.info/wp-content/uploads/2010/03/wmi1-300x258.jpg" alt="" width="300" height="258" /></a><em> </em></p>
<p>Lors de l&#8217;étape 5 le nom des sous-dossier à surveiller sont dans le dossier <em>&#8216;Win32_Directory.Name=&#8221;"F:\WINDOWS\SYSVOL\domain\Policies&#8221;"&#8216;&#8221;</em>, ce qui correspond à l&#8217;emplacement de tous les sous répertoires  <em>{%GPO_GUID%} </em>du dossier incluant les politiques du SYSVOL.</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2010/03/wmi2.jpg" rel=”lightbox” title="wmi property" rel="lightbox[276]"><img class="aligncenter size-medium wp-image-283" title="wmi property" src="http://www.ldap389.info/wp-content/uploads/2010/03/wmi2-300x168.jpg" alt="" width="300" height="168" /></a></p>
<p>Ce qui nous donne la requête WMI suivante:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2010/03/wmi3.jpg" rel=”lightbox” "wmi code" rel="lightbox[276]"><img class="aligncenter size-medium wp-image-284" title="wmi code" src="http://www.ldap389.info/wp-content/uploads/2010/03/wmi3-300x107.jpg" alt="" width="300" height="107" /></a></p>
<p>Pour plus d&#8217;information concernant les requêtes asynchrones en WMI vous pouvez lire cet <a href="http://msdn.microsoft.com/en-us/library/aa393865(VS.85).aspx">article</a>.  Nous pouvons avec ce type de requête enregistrer plusieurs événements accessibles via le WMI arrivant en même temps sur une machine. Avec le script suivant nous allons pouvoir enregistrer la création/suppression de dossiers <em>{%GPO_GUID%} </em>sur le SYSVOL:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #151B8D; font-weight: bold;">On</span> <span style="color: #151B8D; font-weight: bold;">error</span> <span style="color: #151B8D; font-weight: bold;">resume</span> <span style="color: #8D38C9; font-weight: bold;">next</span>
strComputer = <span style="color: #800000;">&quot;.&quot;</span>
DomainDN = <span style="color: #800000;">&quot;DC=ldap389,DC=info&quot;</span>
DomainDNSFQDN = <span style="color: #800000;">&quot;ldap389.info&quot;</span>
LAGDC = <span style="color: #800000;">&quot;LAG_DC&quot;</span>
BackupLocationTool = <span style="color: #800000;">&quot;G:\Tool&quot;</span>
Const ForAppending = 8
<span style="color: #151B8D; font-weight: bold;">Set</span> FSO = <span style="color: #E56717; font-weight: bold;">CreateObject</span>(<span style="color: #800000;">&quot;Scripting.FileSystemObject&quot;</span>)
&nbsp;
<span style="color: #151B8D; font-weight: bold;">Set</span> objWMIService = <span style="color: #E56717; font-weight: bold;">GetObject</span>(<span style="color: #800000;">&quot;winmgmts:\\&quot;</span> &amp; strComputer &amp; <span style="color: #800000;">&quot;\root\CIMV2&quot;</span>) 
<span style="color: #151B8D; font-weight: bold;">Set</span> MySink = WScript.<span style="color: #E56717; font-weight: bold;">CreateObject</span>( _
    <span style="color: #800000;">&quot;WbemScripting.SWbemSink&quot;</span>,<span style="color: #800000;">&quot;SINK_&quot;</span>)
&nbsp;
<span style="color: #151B8D; font-weight: bold;">Set</span> MySink2 = WScript.<span style="color: #E56717; font-weight: bold;">CreateObject</span>( _
    <span style="color: #800000;">&quot;WbemScripting.SWbemSink&quot;</span>,<span style="color: #800000;">&quot;SINK2_&quot;</span>)
&nbsp;
objWMIservice.ExecNotificationQueryAsync MySink, _
    <span style="color: #800000;">&quot;SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE &quot;</span> &amp; _
                    <span style="color: #800000;">&quot;TargetInstance ISA 'Win32_SubDirectory'&quot;</span> &amp; _
                    <span style="color: #800000;">&quot; AND TargetInstance.GroupComponent = 'Win32_Directory.Name=&quot;</span><span style="color: #800000;">&quot;F:\\\\WINDOWS\\\\SYSVOL\\\\domain\\\\Policies&quot;</span><span style="color: #800000;">&quot;'&quot;</span>
&nbsp;
objWMIservice.ExecNotificationQueryAsync MySink2, _
    <span style="color: #800000;">&quot;SELECT * FROM __InstanceDeletionEvent WITHIN 10 WHERE &quot;</span> &amp; _
                    <span style="color: #800000;">&quot;TargetInstance ISA 'Win32_SubDirectory'&quot;</span> &amp; _
                    <span style="color: #800000;">&quot; AND TargetInstance.GroupComponent = 'Win32_Directory.Name=&quot;</span><span style="color: #800000;">&quot;F:\\\\WINDOWS\\\\SYSVOL\\\\domain\\\\Policies&quot;</span><span style="color: #800000;">&quot;'&quot;</span>
&nbsp;
<span style="color: #8D38C9; font-weight: bold;">While</span> (<span style="color: #00C2FF; font-weight: bold;">True</span>)
    Wscript.Sleep(1000)
Wend
&nbsp;
<span style="color: #E56717; font-weight: bold;">Sub</span> SINK_OnObjectReady(objObject, objAsyncContext)
	gpofullpath = objObject.TargetInstance.Properties_.item(<span style="color: #800000;">&quot;PartComponent&quot;</span>).value
	gpoid1 = split(lcase(gpofullpath),<span style="color: #800000;">&quot;policies\\&quot;</span>)
	gpouid = replace(gpoid1(1),chr(34),<span style="color: #800000;">&quot;&quot;</span>)
&nbsp;
	strGPODN = <span style="color: #800000;">&quot;CN=&quot;</span>&amp;gpouid&amp;<span style="color: #800000;">&quot;,CN=Policies,CN=System,&quot;</span>&amp;DomainDN
&nbsp;
		<span style="color: #151B8D; font-weight: bold;">Set</span> objGPO = <span style="color: #E56717; font-weight: bold;">GetObject</span>(<span style="color: #800000;">&quot;LDAP://&quot;</span> &amp; strGPODN)
		StrGPOName = objGPO.DisplayName
&nbsp;
	<span style="color: #151B8D; font-weight: bold;">Set</span> df80 = FSO.OpenTextFile(BackupLocationTool&amp;<span style="color: #800000;">&quot;\GPM-Modified.log&quot;</span>,ForAppending)
	df80.writeline(now&amp;<span style="color: #800000;">&quot;;CREATED;&quot;</span>&amp;gpouid&amp;<span style="color: #800000;">&quot;;&quot;</span>&amp;StrGPOName)
	df80.<span style="color: #8D38C9; font-weight: bold;">close</span>
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Sub</span>
&nbsp;
<span style="color: #E56717; font-weight: bold;">Sub</span> SINK2_OnObjectReady(objObject, objAsyncContext)
    gpofullpath = objObject.TargetInstance.Properties_.item(<span style="color: #800000;">&quot;PartComponent&quot;</span>).value
StrGPOName = <span style="color: #800000;">&quot;N/A&quot;</span>
	gpoid1 = split(lcase(gpofullpath),<span style="color: #800000;">&quot;policies\\&quot;</span>)
	gpouid = replace(gpoid1(1),chr(34),<span style="color: #800000;">&quot;&quot;</span>)
		<span style="color: #8D38C9; font-weight: bold;">if</span> LAGDC &lt;&gt; <span style="color: #800000;">&quot;&quot;</span> <span style="color: #8D38C9; font-weight: bold;">then</span>
		strGPODN = <span style="color: #800000;">&quot;CN=&quot;</span>&amp;gpouid&amp;<span style="color: #800000;">&quot;,CN=Policies,CN=System,&quot;</span>&amp;DomainDN
		err.clear
		<span style="color: #151B8D; font-weight: bold;">Set</span> objGPO = <span style="color: #E56717; font-weight: bold;">GetObject</span>(<span style="color: #800000;">&quot;LDAP://&quot;</span> &amp;LAGDC&amp;<span style="color: #800000;">&quot;/&quot;</span>&amp;strGPODN)
		<span style="color: #8D38C9; font-weight: bold;">if</span> err.number &lt;&gt; 0 <span style="color: #8D38C9; font-weight: bold;">then</span>
		StrGPOName = <span style="color: #800000;">&quot;N/A&quot;</span>
		<span style="color: #8D38C9; font-weight: bold;">else</span>
		StrGPOName = objGPO.DisplayName
		<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">if</span>
		<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">if</span>
	<span style="color: #151B8D; font-weight: bold;">Set</span> df80 = FSO.OpenTextFile(BackupLocationTool&amp;<span style="color: #800000;">&quot;\GPM-Modified.log&quot;</span>,ForAppending)
df80.writeline(now&amp;<span style="color: #800000;">&quot;;DELETED;&quot;</span>&amp;gpouid&amp;<span style="color: #800000;">&quot;;&quot;</span>&amp;StrGPOName)
df80.<span style="color: #8D38C9; font-weight: bold;">close</span>
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Sub</span>
&nbsp;
<span style="color: #E56717; font-weight: bold;">Sub</span> SINK_OnCompleted(objObject, objAsyncContext)
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Sub</span></pre></div></div>

<p>Pour télécharger le script c&#8217;est ici:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2010/07/GPM1.txt"><img class="aligncenter size-full wp-image-83" title="tool" src="http://www.ldap389.info/wp-content/uploads/2010/03/tool1.png" alt="" width="48" height="48" /></a></p>
<p>Il faudra changer en début de script les valeurs suivantes:</p>
<ul>
<li>DomainDN = &#8220;DC=ldap389,DC=info&#8221;, le <a href="http://msdn.microsoft.com/en-us/library/aa366101(VS.85).aspx"><em>Distinguished Name</em></a> de votre domaine.</li>
<li>DomainDNSFQDN = &#8220;ldap389.info&#8221;, le FQDN de votre domaine.</li>
<li>BackupLocationTool = &#8220;G:Tool&#8221;, Le dossier se trouvant votre script.</li>
<li>LAGDC = &#8220;LAG_DC&#8221;, Si vous voulez le connaître le nom de la GPO supprimée et pas seulement son GUID, il vous faudra <a href="http://blogs.technet.com/askds/archive/2008/10/20/lag-site-or-hot-site-aka-delayed-replication-for-active-directory-disaster-recovery-support.aspx">un site de LAG</a>, le DC sur le LAG SITE va vous permettre de connaître le <em>displayname</em> de la GPO supprimée. Si vous n&#8217;avez pas de DC avec une replication retardée mettre LAGDC = &#8220;&#8221;</li>
</ul>
<p>Il ne vous reste plus qu&#8217;a surveiller les fichiers <em>GPT.INI </em>modifiés sur la partition hébergeant le SYSVOL, pour cela utiliser le code suivant:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">objWMIservice.ExecNotificationQueryAsync MySink3, _
    <span style="color: #800000;">&quot;SELECT * FROM __InstanceModificationEvent WITHIN 60 WHERE &quot;</span> &amp; _
                    <span style="color: #800000;">&quot;TargetInstance ISA 'CIM_DataFile'&quot;</span> &amp; _
                    <span style="color: #800000;">&quot; AND TargetInstance.Drive = 'F:'&quot;</span> &amp; _
                    <span style="color: #800000;">&quot; AND TargetInstance.Extension = 'ini'&quot;</span> &amp; _
                    <span style="color: #800000;">&quot; AND TargetInstance.FileName = 'gpt'&quot;</span>
&nbsp;
<span style="color: #E56717; font-weight: bold;">Sub</span> SINK3_OnObjectReady(objObject, objAsyncContext)
&nbsp;
<span style="color: #8D38C9; font-weight: bold;">if</span> objObject.TargetInstance.Properties_.item(<span style="color: #800000;">&quot;LastModified&quot;</span>).value &lt;&gt; objObject.PreviousInstance.Properties_.item(<span style="color: #800000;">&quot;LastModified&quot;</span>).value <span style="color: #8D38C9; font-weight: bold;">then</span>
	gpofullpath = objObject.TargetInstance.Properties_.item(<span style="color: #800000;">&quot;Name&quot;</span>).value
&nbsp;
	<span style="color: #8D38C9; font-weight: bold;">if</span> instr(gpofullpath,DomainDNSFQDN) = 0 <span style="color: #8D38C9; font-weight: bold;">then</span>
&nbsp;
		gpoid1 = split(lcase(gpofullpath),<span style="color: #800000;">&quot;policies\&quot;</span>)
&nbsp;
		gpoid2 = split(lcase(gpoid1(1)),<span style="color: #800000;">&quot;\gpt.ini&quot;</span>)
		gpouid = gpoid2(0)
&nbsp;
		strGPODN = <span style="color: #800000;">&quot;CN=&quot;</span>&amp;gpouid&amp;<span style="color: #800000;">&quot;,CN=Policies,CN=System,&quot;</span>&amp;DomainDN
		<span style="color: #151B8D; font-weight: bold;">Set</span> objGPO = <span style="color: #E56717; font-weight: bold;">GetObject</span>(<span style="color: #800000;">&quot;LDAP://&quot;</span> &amp; strGPODN)
		StrGPOName = objGPO.DisplayName
&nbsp;
	<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">if</span>
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">if</span>
&nbsp;
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Sub</span></pre></div></div>

<p>Pour télécharger c&#8217;est ici:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2010/07/GPM2.txt"><img class="aligncenter size-full wp-image-83" title="tool" src="http://www.ldap389.info/wp-content/uploads/2010/03/tool1.png" alt="" width="48" height="48" /></a></p>
<p>Si vous monitorez avec WMI  les modifications d&#8217;un système de fichiers vous pouvez lire ce <a href="http://blogs.technet.com/heyscriptingguy/archive/2005/04/04/how-can-i-monitor-for-different-types-of-events-with-just-one-script.aspx">post</a> des scripting guy&#8217;s. Nous avons donc maintenant notre script de monitoring des GPOs, ce script une fois adapté fonctionne si vous n&#8217;avez pas un SYSVOL trop conséquent.</p>
<p>Si vous avez beaucoup de GPOs dans votre domaine il se peut que vous soyez limité par les <a href="http://blogs.technet.com/askperf/archive/2008/09/16/memory-and-handle-quotas-in-the-wmi-provider-service.aspx">quotas WMI</a> dans votre requête. L&#8217;erreur est du type <em>wmi quota violation 0x8004106C (</em> pour les codes d&#8217;erreur WMI c&#8217;est <a href="http://msdn.microsoft.com/en-us/library/aa394559(VS.85).aspx">ici</a>). Sur notre SYSVOL nous avons plus de 3500 GPOs, le script WMI crashait au bout de quelques minutes, nous avons donc utilisé wbemtest.exe pour changer les valeurs de la super classe  <a href="http://msdn.microsoft.com/en-us/library/aa393013%28VS.85%29.aspx#subscription_quotas">__ArbitratorConfiguration</a> de la manière suivante:  %Total = %PerUser de façon à lancer ce script en tant que service avec un compte dédié, sans limitations de quota utilisateur liées à WMI, seul un quota total est respecté. Attendez vous donc à avoir une charge CPU/Mémoire supplémentaire sur ce DC si vous avez un nombre conséquent d&#8217;objets de stratégie de groupe à surveiller. Graph CPU pour un Dual Core 2,5GHz surveillant 3500 GPOs:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2010/03/cpu_dc.jpg" title="cpu dc" rel=”lightbox” rel="lightbox[276]"><img class="aligncenter size-medium wp-image-299" title="cpu dc" src="http://www.ldap389.info/wp-content/uploads/2010/03/cpu_dc-300x116.jpg" alt="" width="300" height="116" /></a></p>
<p>Nous allons voir maintenant voir comment créer un service à partir d&#8217;un script VBS, pour cela <a href="http://www.visualbasicscript.com/m67553.aspx">lire cet article</a> très bien expliqué. Voici ce que cela donne pour notre outil:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2010/03/vbsservice.jpg" rel=”lightbox” title="vbs service" rel="lightbox[276]"><img class="aligncenter size-medium wp-image-296" title="vbs service" src="http://www.ldap389.info/wp-content/uploads/2010/03/vbsservice-300x32.jpg" alt="" width="300" height="32" /></a></p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2010/03/vbs_service2.jpg" rel=”lightbox” title="vbs_service" rel="lightbox[276]"><img class="aligncenter size-medium wp-image-297" title="vbs_service" src="http://www.ldap389.info/wp-content/uploads/2010/03/vbs_service2-300x107.jpg" alt="" width="300" height="107" /></a></p>
<p>Ajoutez une dépendance au service WMI:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2010/03/vbsservice3.jpg" rel=”lightbox” title="dependancy service" rel="lightbox[276]"><img class="aligncenter size-medium wp-image-298" title="dependancy service" src="http://www.ldap389.info/wp-content/uploads/2010/03/vbsservice3-300x124.jpg" alt="" width="300" height="124" /></a></p>
<p>Et voila, votre service de surveillance du SYSVOL est en place.</p>
<p>Vous savez maintenant comment surveiller les principaux changements d&#8217;objets de stratégie de groupe au niveau GPT sur votre infrascture. L&#8217;objet du prochain post est le monitoring des liens de GPOs, ce qui veut dire sur quels containers s&#8217;appliquent vos GPOs, pour cela nous surveillerons l&#8217;attribut GPLink audité<a href="http://technet.microsoft.com/en-us/library/cc773209(WS.10).aspx"> par défaut</a>, au niveau unité d&#8217;organisation et site, sur votre AD . Voir le tableau suivant: </p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2010/03/gplinktab.jpg" rel=”lightbox” title="gplink audit" rel="lightbox[276]"><img class="aligncenter size-medium wp-image-294" title="gplink audit" src="http://www.ldap389.info/wp-content/uploads/2010/03/gplinktab-300x195.jpg" alt="" width="300" height="195" /></a></p>
<p>Une fois les changements de <a href="http://technet.microsoft.com/en-us/library/ee461061.aspx">GPLinks</a> sur une <a href="http://www.netid.washington.edu/documentation/gpoOrder.aspx">OU/site/domaine</a> détectés,  vous pourrez connaitre les modifications importantes de GPOs sur votre domaine:</p>
<ul>
<li>Création de GPO</li>
<li>Suppression de GPO</li>
<li>Modification de paramètre Ordinateur/Utilisateur de la GPO.</li>
<li>Modification/suppression/création d&#8217;un lien de GPO. </li>
</ul>
<p>La suite bientot.</p>
<div class="tweetthis" style="text-align:left;"><p> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=Surveiller+les+changements+des+GPOs+%3A+Monitorer+le+SYSVOL+http%3A%2F%2Fis.gd%2Ftz3gVt" title="Post to Twitter"><img class="nothumb" src="http://www.ldap389.info/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter-micro3.png" alt="Post to Twitter" /></a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.ldap389.info/2010/03/26/surveiller-changement-gpo-sysvol/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Identifier une application nuisant à la performance de votre domain controller</title>
		<link>http://www.ldap389.info/2010/03/20/identifier-application-nuisant-performance-dc/</link>
		<comments>http://www.ldap389.info/2010/03/20/identifier-application-nuisant-performance-dc/#comments</comments>
		<pubDate>Sat, 20 Mar 2010 17:20:27 +0000</pubDate>
		<dc:creator>ldap389</dc:creator>
				<category><![CDATA[tools]]></category>
		<category><![CDATA[troubleshooting]]></category>
		<category><![CDATA[cpu]]></category>
		<category><![CDATA[lsass]]></category>

		<guid isPermaLink="false">http://www.ldap389.info/?p=230</guid>
		<description><![CDATA[Nous allons voir dans ce post comment identifier un application entraînant une consommation de CPU anormale sur vos Domain Controllers. Nous allons pour cela utiliser principalement deux outils: Server Performance Advisor et Wireshark. Le premier outil est utile si votre DC est sous Windows 2003, si vous êtes sous 2008, celui ci est inclus dans l&#8217;OS via le composant [...]]]></description>
			<content:encoded><![CDATA[<p>Nous allons voir dans ce post comment identifier un application entraînant une consommation de CPU anormale sur vos Domain Controllers. Nous allons pour cela utiliser principalement deux outils: <a href="http://www.microsoft.com/downloads/details.aspx?familyid=61a41d78-e4aa-47b9-901b-cf85da075a73&amp;displaylang=en">Server Performance Advisor</a> et<a href="http://www.wireshark.org/"> Wireshark</a>. Le premier outil est utile si votre DC est sous Windows 2003, si vous êtes sous 2008, celui ci est inclus dans l&#8217;OS via le composant logiciel enfichable <em>perfmon.msc</em>, son nouveau nom <a href="http://technet.microsoft.com/en-us/library/cc755081(WS.10).aspx">Windows Reliability and Performance Monitor</a>. La version 2003 et la 2008 possèdent des modules dédiés pour Active Directory, nous allons utiliser SPA, car le DC impacté est un 2003, si vous voulez plus de détails sur RPM et Active Directory vous pouvez lire <a href="http://www.activedir.org/Articles/tabid/54/articleType/ArticleView/articleId/49/Default.aspx">cet article</a>.<br />
<span id="more-230"></span><br />
En analysant la courbe CPU d&#8217;un de nos DCs sous Windows 2003 nous avons remarqué une consommation anormale du process lsass.exe:</p>
<p><a title="graphlsass1" rel="lightbox" href="http://www.ldap389.info/wp-content/uploads/2010/03/graphcpu1.jpg"><img class="aligncenter size-medium wp-image-231" title="graphcpu1" src="http://www.ldap389.info/wp-content/uploads/2010/03/graphcpu1-300x126.jpg" alt="" width="300" height="126" /></a></p>
<p>On voit que le DC est particulièrement sollicité aux horaires de bureau, la piste d&#8217;une application utilisée par les postes clients nuisant aux performances du DC semble donc la plus plausible. Nous laçons donc une analyse avec SPA sur le DC impacté dont voici le résultat:</p>
<p><a title="server performance advisor" rel="lightbox" href="http://www.ldap389.info/wp-content/uploads/2010/03/spa.jpg"><img class="aligncenter size-medium wp-image-233" title="spa" src="http://www.ldap389.info/wp-content/uploads/2010/03/spa-300x147.jpg" alt="" width="300" height="147" /></a></p>
<p>La requête <em>SamEnumUsersInDomain </em>nous prend 42% de CPU, l&#8217;IP des clients provoquant ces requêtes n&#8217;est malheureusement pas remontée de manière claire via l&#8217;outil, nous allons donc utiliser <a href="http://www.wireshark.org/">WireShark</a>  pour analyser l&#8217;activité réseau de notre DC et identifier les clients:</p>
<p><a title="wireshark" rel="lightbox" href="http://www.ldap389.info/wp-content/uploads/2010/03/wireshark.jpg"><img class="aligncenter size-medium wp-image-234" title="wiresharkanalysis" src="http://www.ldap389.info/wp-content/uploads/2010/03/wireshark-300x139.jpg" alt="" width="300" height="139" /></a></p>
<p>Après un peu d&#8217;analyse des trames nous voyons que le protocole de communication Windows (MCPP) utilisé par ces requêtes est <a href="http://msdn.microsoft.com/en-us/library/cc245476(PROT.10).aspx">MS-SAMR</a>, il nous suffit d&#8217;utiliser le filtre Wireshark correspondant (SAMR) pour identifier les clients. Après avoir envoyé la liste de ces derniers au service informatique du site impacté il s&#8217;est avéré que ce sont des portables avec le logiciel <a href="http://h20219.www2.hp.com/Hpsub/cache/292230-0-0-225-121.html">HP ProtectTools security manager</a> installé. Celui ci a été retiré de la plupart des postes, car les SMART cards n&#8217;étaient pas utilisées, et le résultat a été immédiat sur la courbe CPU des DCs:</p>
<p><a title="graphlsass.exe" rel="lightbox" href="http://www.ldap389.info/wp-content/uploads/2010/03/graphcpu2.jpg"><img class="aligncenter size-medium wp-image-235" title="graphcpu2" src="http://www.ldap389.info/wp-content/uploads/2010/03/graphcpu2-300x115.jpg" alt="" width="300" height="115" /></a> </p>
<p>Afin de d&#8217;identifier sur la partie cliente le processus émettant via un protocole particulier vers une autre machine vous pouvez utiliser le logiciel <a href="http://technet.microsoft.com/en-us/sysinternals/bb897437.aspx">TCPview</a> ou bien <a href="http://www.nirsoft.net/utils/cports.html">CurrPorts</a> que mon collègue de CTXBlog présente dans cet <a href="http://ctxblog.fr/index.php?post/2010/03/13/CurrPorts">article</a>.</p>
<p>Le problème concernant l&#8217;application HP ProtectTools a été discutée sur un des <a href="http://forums13.itrc.hp.com/service/forums/bizsupport/questionanswer.do?admit=109447627+1269095403903+28353475&amp;threadId=1326693">forums HP</a>, la solution serait de passer le Sp41408 de l&#8217;application, cependant nous avons fait le choix de désinstaller cette application, car elle était inutile pour nous.</p>
<div class="tweetthis" style="text-align:left;"><p> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=Identifier+une+application+nuisant+%C3%A0+la+performance+de+votre+domain+controller+http%3A%2F%2Fis.gd%2FKPEaAw" title="Post to Twitter"><img class="nothumb" src="http://www.ldap389.info/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter-micro3.png" alt="Post to Twitter" /></a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.ldap389.info/2010/03/20/identifier-application-nuisant-performance-dc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Outil de diagnostic pour hotline SN1-Info v1.0</title>
		<link>http://www.ldap389.info/2010/03/12/outil-de-diagnostic-pour-hotline-sn1-info-v1-0/</link>
		<comments>http://www.ldap389.info/2010/03/12/outil-de-diagnostic-pour-hotline-sn1-info-v1-0/#comments</comments>
		<pubDate>Fri, 12 Mar 2010 12:08:17 +0000</pubDate>
		<dc:creator>ldap389</dc:creator>
				<category><![CDATA[scripts]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[rsop]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[wmi]]></category>

		<guid isPermaLink="false">http://www.ldap389.info/?p=70</guid>
		<description><![CDATA[Voici une application pour votre support niveau 1 qui peut aider au diagnostic d&#8217;incidents, elle est développé au format HTA. Afin de réaliser cet outil WMI code creator a été d&#8217;une grande utilitée. Cliquer sur l&#8217;icône ci dessous pour télécharger l&#8217;outil, si vous avez des demandes d&#8217;évolution ou des bugs constatés n&#8217;hesitez pas à me [...]]]></description>
			<content:encoded><![CDATA[<p>Voici une application pour votre support niveau 1 qui peut aider au diagnostic d&#8217;incidents, elle est développé au format <a href="http://fr.wikipedia.org/wiki/.hta">HTA</a>. Afin de réaliser cet outil <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=2cc30a64-ea15-4661-8da4-55bbc145c30e&amp;displaylang=en">WMI code creator</a> a été d&#8217;une grande utilitée.</p>
<p>Cliquer sur l&#8217;icône ci dessous pour télécharger l&#8217;outil, si vous avez des demandes d&#8217;évolution ou des bugs constatés n&#8217;hesitez pas à me les faire parvenir, il s&#8217;agit d&#8217;une v1.0.</p>
<div><a href="http://www.ldap389.info/wp-content/uploads/2010/03/SN1-info.zip" target="_blank"><img class="aligncenter size-full wp-image-83" title="tool" src="http://www.ldap389.info/wp-content/uploads/2010/03/tool1.png" alt="" width="48" height="48" /></a></div>
<p><span id="more-70"></span></p>
<p>Une fois l&#8217;outil lancé, entrez le nom du poste distant:</p>
<p><a title="enter computername" rel="lightbox" href="http://www.ldap389.info/wp-content/uploads/2010/03/screen1.jpg"><img class="aligncenter size-medium wp-image-71" title="click to enlarge" src="http://www.ldap389.info/wp-content/uploads/2010/03/screen1-300x124.jpg" alt="" width="300" height="124" /></a></p>
<p>Puis le login utilisateur au format domainelogin:</p>
<p><a title="enter domainusername" rel="lightbox" href="http://www.ldap389.info/wp-content/uploads/2010/03/screen2.jpg"><img class="aligncenter size-medium wp-image-72" title="click to enlarge" src="http://www.ldap389.info/wp-content/uploads/2010/03/screen2-300x126.jpg" alt="" width="300" height="126" /></a></p>
<p>Une fenêtre composée de cinq onglets s&#8217;affiche:</p>
<p><strong><span style="text-decoration: underline;">General info:</span></strong></p>
<p>Cet onglet est découpé en deux sections, la première n&#8217;a rien d&#8217;extraordinaire, se sont des requêtes WMI de base:</p>
<p><a title="general info" rel="lightbox" href="http://www.ldap389.info/wp-content/uploads/2010/03/generalinfo.jpg"><img class="aligncenter size-medium wp-image-74" title="click to enlarge" src="http://www.ldap389.info/wp-content/uploads/2010/03/generalinfo-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p>La seconde &#8220;Network info&#8221; est plus intéressante:  Si nous parcourons la classe WMI <strong>Win32_NetworkAdapterConfiguration </strong>sur un serveur possédant des cartes en Teaming, ou bien sur un portable alors un nombre élevé de cartes nous est retourné, alors que l&#8217;information de seulement une voir deux cartes réseau nous intéresse généralement. Un post des <a href="http://blogs.technet.com/heyscriptingguy/archive/2008/09/08/how-do-i-find-information-about-the-network-adapter-cards-on-my-computer.aspx">scripting guys</a> m&#8217;a donné la solution:  Il nous faut filter tout d&#8217;abord les cartes réseau qui sont connectées à un réseau via la valeur &#8220;NetConnectionStatus&#8221; de la classe WMI <strong>Win32_NetworkAdapter</strong>,  puis énumérer les informations de  <strong>Win32_NetworkAdapterConfiguration </strong>pour les cartes qui ont une IP d&#8217;activée (valeur IPEnabled). La valeur commune entre ses deux classes est &#8220;caption&#8221;. Ce qui nous donne les deux requêtes suivantes que vous retrouverez dans le code du fichier HTA.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #151B8D; font-weight: bold;">Set</span> colItems = objWMIService.ExecQuery(<span style="color: #800000;">&quot;SELECT caption FROM Win32_NetworkAdapter WHERE NetConnectionStatus = 2&quot;</span>)
<span style="color: #8D38C9; font-weight: bold;">For</span> <span style="color: #8D38C9; font-weight: bold;">Each</span> objItem <span style="color: #8D38C9; font-weight: bold;">in</span> colItems
caption1 = objItem.caption
<span style="color: #151B8D; font-weight: bold;">Set</span> colNicConfigs = objWMIService.ExecQuery(<span style="color: #800000;">&quot;SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True AND caption = '&quot;</span>&amp;caption1&amp;<span style="color: #800000;">&quot;'&quot;</span>)
<span style="color: #8D38C9; font-weight: bold;">For</span> <span style="color: #8D38C9; font-weight: bold;">Each</span> objNicConfig <span style="color: #8D38C9; font-weight: bold;">In</span> colNicConfigs
<span style="color: #008000;">'Retrieve IP adress, DNS servers....
</span><span style="color: #8D38C9; font-weight: bold;">Next</span>
<span style="color: #8D38C9; font-weight: bold;">Next</span></pre></td></tr></table></div>

<p>Passons aux informations du second onglet.</p>
<p><strong><span style="text-decoration: underline;">Printers:</span></strong></p>
<p>Pour cet onglet nous utilisons toujours WMI pour lister les imprimantes, le nom de driver est indiqué ainsi que le type:  Imprimante réseau ou locale. L&#8217;imprimante par défaut est surlignée en bleu.</p>
<p><a title="printers" rel="lightbox" href="http://www.ldap389.info/wp-content/uploads/2010/03/printers.jpg"><img class="aligncenter size-medium wp-image-75" title="click to enlarge" src="http://www.ldap389.info/wp-content/uploads/2010/03/printers-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p>Afin de déterminer si il s&#8217;agit d&#8217;une imprimante réseau ou locale voir un autre post des <a href="http://blogs.technet.com/heyscriptingguy/archive/2007/11/02/hey-scripting-guy-how-can-i-remove-all-the-network-printers-on-a-computer.aspx">scripting guys</a>, l&#8217;outil est compatible avec Windows2000 et versions d&#8217;après, en utilisant la méthodologie mentionnée dans le lien. Malgré tout il a été constaté que parfois les imprimantes réseau ne sont pas remontées par une requête WMI à distance, dans ce cas nous nous basons sur la clef de registre HKCU\Printers\Connections (HKUSERS\%SID_Utilisateur%\Printers\Connections), l&#8217;imprimante par défaut ne peut alors être découverte, ni le driver. L&#8217;impossibilité d&#8217;énumérer les imprimantes réseau à distance est lié au fait que votre compte n&#8217;a pas les droits de lecture pour interroger ce &#8220;namespace&#8221; WMI car elles sont déclarées au niveau utilisateur, il faudrait alors exécuter notre script avec les credentials de l&#8217;utilisateur connecté, pour faire cela via WMI voir cet <a href="http://msdn.microsoft.com/en-us/library/aa389290%28VS.85%29.aspx#specifying_credentials_and_an_authentication_level_for_the_remote_connection">article</a>.</p>
<p><strong><span style="text-decoration: underline;">Active Directory:</span></strong></p>
<p>La première information indique le DC de logon utilisé par la session de l&#8217;utilisateur distant. Puis le résultat d&#8217;un RSOP est affiché, nous avons listé les GPO appliquées sur la partie ordinateur, puis utilisateur:</p>
<p><a title="active directory" rel="lightbox" href="http://www.ldap389.info/wp-content/uploads/2010/03/activdir.jpg"><img class="aligncenter size-medium wp-image-77" title="click to enlarge" src="http://www.ldap389.info/wp-content/uploads/2010/03/activdir-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p>La classe WMI <strong>rootrsopcomputer </strong>est utilisée pour obtenir la configuration ordinateur des GPOs, pour la configuration utilisateur c&#8217;est un peu moins évident. En effet il faut faire appel à la classe <strong>root\rsop\user\%SID_Utilisateur% </strong>mais il faut remplacer les &#8220;-&#8221; de votre SID par des &#8220;_&#8221;. Ce qui donne le code suivant:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #151B8D; font-weight: bold;">Set</span> objAccount = objWMIService.<span style="color: #151B8D; font-weight: bold;">Get</span>(<span style="color: #800000;">&quot;Win32_UserAccount.Name='&quot;</span>&amp;usser&amp;<span style="color: #800000;">&quot;',Domain='&quot;</span>&amp;domaine&amp;<span style="color: #800000;">&quot;'&quot;</span>)
SID=replace(objAccount.SID,<span style="color: #800000;">&quot;-&quot;</span>,<span style="color: #800000;">&quot;_&quot;</span>)
<span style="color: #151B8D; font-weight: bold;">Set</span> objWMIGPO = <span style="color: #E56717; font-weight: bold;">GetObject</span>(<span style="color: #800000;">&quot;winmgmts:&quot;</span> &amp; strComputer &amp; <span style="color: #800000;">&quot;root\rsop\user&quot;</span>&amp;SID)
&nbsp;
<span style="color: #151B8D; font-weight: bold;">Set</span> colGPO = objWMIGPO.ExecQuery(<span style="color: #800000;">&quot;Select * from RSOP_GPO&quot;</span>)
&nbsp;
<span style="color: #8D38C9; font-weight: bold;">For</span> <span style="color: #8D38C9; font-weight: bold;">Each</span> objGPO <span style="color: #8D38C9; font-weight: bold;">in</span> colGPO
version = hex(objGPO.Version)
version = right(version,4)
version = CLng(<span style="color: #800000;">&quot;&amp;H&quot;</span> &amp; version)
<span style="color: #008000;">'Collect other information
</span><span style="color: #8D38C9; font-weight: bold;">Next</span></pre></td></tr></table></div>

<p>Comme vous pouvez le voir ci dessus la version de la GPO n&#8217;est aussi pas évidente à obtenir car il s&#8217;agit d&#8217;une combinaison de la version GPT et du GPC, dans notre script nous nous basons sur le GPC. Pour plus d&#8217;informations sur la classe <strong>root\rsop</strong> c&#8217;est <a href="http://msdn.microsoft.com/en-us/library/aa374918(VS.85).aspx">ici</a>.</p>
<p><strong><span style="text-decoration: underline;">Hotfixes:</span></strong></p>
<p>Sur cet onglet nous indiquons si Windows Update est activé et si un serveur WSUS est utilisé pour les mise à jour, toutes ces informations sont accessibles via le <a href="http://support.microsoft.com/kb/328010">registre</a>, la liste des KB est récupérée via WMI.</p>
<p><a title="hotfixes" rel="lightbox" href="http://www.ldap389.info/wp-content/uploads/2010/03/hotfix.jpg"><img class="aligncenter size-medium wp-image-79" title="click to enlarge" src="http://www.ldap389.info/wp-content/uploads/2010/03/hotfix-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p><strong><span style="text-decoration: underline;">Citrix:</span></strong></p>
<p>Nous avons la version du client ICA installée, voir cette vieille <a href="http://support.citrix.com/article/CTX229784">CTX</a> pour la méthode. Puis l&#8217;URL du PN Agent est indiquée si celle ci est configurée.</p>
<p><a title="citrix" rel="lightbox" href="http://www.ldap389.info/wp-content/uploads/2010/03/citrix1.jpg"><img class="aligncenter size-medium wp-image-82" title="click to enlarge" src="http://www.ldap389.info/wp-content/uploads/2010/03/citrix1-300x225.jpg" alt="" width="300" height="225" /></a></p>
<div class="tweetthis" style="text-align:left;"><p> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=Outil+de+diagnostic+pour+hotline+SN1-Info+v1.0+http%3A%2F%2Fis.gd%2FEkuVra" title="Post to Twitter"><img class="nothumb" src="http://www.ldap389.info/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter-micro3.png" alt="Post to Twitter" /></a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.ldap389.info/2010/03/12/outil-de-diagnostic-pour-hotline-sn1-info-v1-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

