<?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; scripts</title>
	<atom:link href="http://www.ldap389.info/category/scripts/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>Windows 8: Installer une PKI ADCS</title>
		<link>http://www.ldap389.info/2012/01/24/windows-8-installer-pki-powershell-adcs/</link>
		<comments>http://www.ldap389.info/2012/01/24/windows-8-installer-pki-powershell-adcs/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 20:30:55 +0000</pubDate>
		<dc:creator>ldap389</dc:creator>
				<category><![CDATA[Public Key Infrastructure]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[pki]]></category>
		<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">http://www.ldap389.info/?p=1680</guid>
		<description><![CDATA[Nous allons voir dans ce post comment installer une PKI sous Windows 8 Developer Preview, et voir que Powershell arrive en natif pour configurer notre PKI. Tout d&#8217;abord nous allons ajouter le rôle ADCS via Server Manager: Choisir ensuite &#8220;Role-based installation or Feature-based installation&#8220;, passer à l&#8217;écran suivant. Dans Server Manager nous allons ensuite sélectionner un [...]]]></description>
			<content:encoded><![CDATA[<p>Nous allons voir dans ce post comment installer une PKI sous <em>Windows 8 Developer Preview, </em>et voir que Powershell arrive en natif pour configurer notre PKI.</p>
<p>Tout d&#8217;abord nous allons ajouter le rôle ADCS via <em>Server Manager</em>:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2012/01/install-ca1.jpg" rel="lightbox[1680]"><img class="aligncenter size-medium wp-image-1681" title="install-ca1" src="http://www.ldap389.info/wp-content/uploads/2012/01/install-ca1-300x155.jpg" alt="" width="300" height="155" /></a><br />
<span id="more-1680"></span><br />
Choisir ensuite &#8220;<em>Role-based installation or Feature-based installation</em>&#8220;, passer à l&#8217;écran suivant. Dans <em>Server Manager</em> nous allons ensuite sélectionner un serveur sur lequel installer le rôle, sur Windows 8 nous pouvons gérer des <a href="http://www.windowsitpro.com/article/windowsserver8/server-management-windows-server-8-140938">serveurs distants</a> <img src='http://www.ldap389.info/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2012/01/install-ca3.jpg" rel="lightbox[1680]"><img class="aligncenter size-medium wp-image-1682" title="install-ca3" src="http://www.ldap389.info/wp-content/uploads/2012/01/install-ca3-300x166.jpg" alt="" width="300" height="166" /></a></p>
<p>Choisir le rôle <em>Active Directory Certificate Services</em>:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2012/01/install-ca4.jpg" rel="lightbox[1680]"><img class="aligncenter size-medium wp-image-1683" title="install-ca4" src="http://www.ldap389.info/wp-content/uploads/2012/01/install-ca4-300x130.jpg" alt="" width="300" height="130" /></a></p>
<p>Passer l&#8217;écran <em>Features</em>, puis dans les <em>role services</em> nous ne choisissons que <em>Certification Authority</em>:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2012/01/install-ca5.jpg" rel="lightbox[1680]"><img class="aligncenter size-medium wp-image-1684" title="install-ca5" src="http://www.ldap389.info/wp-content/uploads/2012/01/install-ca5-300x139.jpg" alt="" width="300" height="139" /></a></p>
<p>Valider l&#8217;écran d&#8217;après pour commencer l&#8217;installation du rôle. Maintenant nous ouvrons une session Powershell sur le serveur sur lequel le rôle a été installé et lançons la commande:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;">Get<span style="color: pink;">-</span>Module –ListAvailable</pre></div></div>

<p>On remarque l&#8217;apparition d&#8217;un nouveau module: <em>CertificateServicesCmdlets</em>.</p>
<p>Listons les Cmdlets de ce module avec:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #000000;">&#40;</span>get<span style="color: pink;">-</span>module CertificateServicesCmdlets<span style="color: #000000;">&#41;</span>.exportedcommands</pre></div></div>

<p>Voilà la liste des cmdlets disponibles:</p>
<blockquote><p>Get-AdcsCertificationAuthorityConfigurationDefaults<br />
Get-AdcsConfigurationState<br />
Get-AdcsEnrollmentPolicyWebServiceConfigurationDefaults<br />
Get-AdcsEnrollmentWebServiceConfigurationDefaults<br />
Get-AdcsNetworkDeviceEnrollmentConfigurationDefaults<br />
Get-SSLCertificates<br />
Import-AdcsCertificationAuthorityCACertificatePfx<br />
Install-AdcsCertificationAuthority<br />
Install-AdcsEnrollmentPolicyWebService<br />
Install-AdcsEnrollmentWebService<br />
Install-AdcsNetworkDeviceEnrollmentService<br />
Install-AdcsOnlineResponder<br />
Install-AdcsWebEnrollment<br />
Uninstall-AdcsCertificationAuthority<br />
Uninstall-AdcsEnrollmentPolicyWebService<br />
Uninstall-AdcsEnrollmentWebService<br />
Uninstall-AdcsNetworkDeviceEnrollmentService<br />
Uninstall-AdcsOnlineResponder<br />
Uninstall-AdcsWebEnrollment</p></blockquote>
<p>Nous allons donc utiliser le cmdlet<em> Install-AdcsCertificationAuthority</em> pour configurer notre serveur rootCA. En s&#8217;inspirant de ce que le script <a href="http://blogs.technet.com/b/pki/archive/2009/09/18/automated-ca-installs-using-vb-script-on-windows-server-2008-and-2008r2.aspx">setupCA.vbs</a> faisait nous lançons la commande suivante:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;">Install<span style="color: pink;">-</span>AdcsCertificationAuthority <span style="color: pink;">-</span>CAType EnterpriseRootCA <span style="color: pink;">-</span>CACommonName LDAP389<span style="color: pink;">-</span>CA <span style="color: pink;">-</span>KeyLength <span style="color: #804000;">4096</span> <span style="color: pink;">-</span>HashAlgorithmName SHA256 <span style="color: pink;">-</span>CryptoProviderName <span style="color: #800000;">&quot;RSA#Microsoft Software Key Storage Provider&quot;</span></pre></div></div>

<p>Et voilà, notre RootCA est installé, nous lançons la console <em>Certification Authority</em> et on vérifie que notre installation est conforme aux paramètres configurés via PowerShell:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2012/01/ca-certificate.jpg" rel="lightbox[1680]"><img class="aligncenter size-medium wp-image-1686" title="ca-certificate" src="http://www.ldap389.info/wp-content/uploads/2012/01/ca-certificate-300x212.jpg" alt="" width="300" height="212" /></a></p>
<p>Sous Windows 8 on pourra donc configurer notre PKI avec Powershell, mais peut-être pas nous passer de l&#8217;excellent <a href="http://en-us.sysadmins.lv/Lists/Posts/Post.aspx?ID=58">PS PKI module</a> de Powershell Crypto Guy, l&#8217;avenir nous le dira <img src='http://www.ldap389.info/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><strong>Attention:</strong> Comme il s’agit d’une <em>Developer Preview</em> ces cmdlets ainsi que la procédure d&#8217;installation ne sont peut être pas définitifs.</p>
<div class="tweetthis" style="text-align:left;"><p> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=Windows+8%3A+Installer+une+PKI+ADCS+http%3A%2F%2Fis.gd%2FWrvGHP" 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/2012/01/24/windows-8-installer-pki-powershell-adcs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows 8: Gérer la replication AD avec Powershell</title>
		<link>http://www.ldap389.info/2012/01/08/windows-8-gerer-la-replication-ad-avec-powershell/</link>
		<comments>http://www.ldap389.info/2012/01/08/windows-8-gerer-la-replication-ad-avec-powershell/#comments</comments>
		<pubDate>Sun, 08 Jan 2012 14:02:58 +0000</pubDate>
		<dc:creator>ldap389</dc:creator>
				<category><![CDATA[scripts]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[repadmin]]></category>

		<guid isPermaLink="false">http://www.ldap389.info/?p=1642</guid>
		<description><![CDATA[J&#8217;ai enfin trouvé un peu de temps pour installer dans un lab mes premiers DCs sous Windows 8 Developer Preview (merci à Vmdude). Dans ce domaine de tests ldap389.local ont été installés deux RWDC nommés ldap389-pdce et ldap389-dc2 situés chacun dans un site AD, pour l&#8217;installation c&#8217;est ici et la. Une fois l&#8217;installation terminée j&#8217;ai lancé la commande Powershell suivante: &#40;get-module [...]]]></description>
			<content:encoded><![CDATA[<p>J&#8217;ai enfin trouvé un peu de temps pour installer dans un lab mes premiers DCs sous <em>Windows 8 Developer Preview </em>(merci à <a href="http://www.vmdude.fr/">Vmdude</a>). Dans ce domaine de tests <em>ldap389.local </em>ont été installés deux RWDC nommés <em>ldap389-pdce</em> et <em>ldap389-dc2 </em>situés chacun dans un site AD, pour l&#8217;installation c&#8217;est <a href="http://jorgequestforknowledge.wordpress.com/2011/11/04/installing-and-uninstalling-ad-on-windows-server-8-as-an-rwdc-and-as-an-rodc-part-1/">ici</a> et <a href="http://jorgequestforknowledge.wordpress.com/2011/11/04/installing-and-uninstalling-ad-on-windows-server-8-as-an-rwdc-and-as-an-rodc-part-2/">la</a>.</p>
<p>Une fois l&#8217;installation terminée j&#8217;ai lancé la commande Powershell suivante:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #000000;">&#40;</span>get<span style="color: pink;">-</span>module ActiveDirectory<span style="color: #000000;">&#41;</span>.exportedcommands</pre></div></div>

<p><span id="more-1642"></span>Ceci afin de lister tous les cmdlets du module Active Directory. On remarque alors l&#8217;apparition, entre autres, de nouveaux cmdlets permettant de gérer la replication ADDS:</p>
<blockquote><p>Get-ADReplicationAttributeMetadata<br />
Get-ADReplicationConnection<br />
Get-ADReplicationFailure<br />
Get-ADReplicationPartnerMetadata<br />
Get-ADReplicationQueueOperation<br />
Get-ADReplicationSite<br />
Get-ADReplicationSiteLink<br />
Get-ADReplicationSiteLinkBridge<br />
Get-ADReplicationSubnet<br />
Get-ADReplicationUpToDatenessVectorTable<br />
New-ADReplicationSite<br />
New-ADReplicationSiteLink<br />
New-ADReplicationSiteLinkBridge<br />
New-ADReplicationSubnet<br />
Remove-ADReplicationSite<br />
Remove-ADReplicationSiteLink<br />
Remove-ADReplicationSiteLinkBridge<br />
Remove-ADReplicationSubnet<br />
Set-ADReplicationConnection<br />
Set-ADReplicationSite<br />
Set-ADReplicationSiteLink<br />
Set-ADReplicationSiteLinkBridge<br />
Set-ADReplicationSubnet</p></blockquote>
<p>La topologie du domaine <em>ldap389.local</em> est la suivante:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2012/01/toplogy-windows8.jpg" rel="lightbox[1642]"><img class="aligncenter size-medium wp-image-1649" title="toplogy-windows8" src="http://www.ldap389.info/wp-content/uploads/2012/01/toplogy-windows8-300x195.jpg" alt="" width="300" height="195" /></a></p>
<p>Nous allons tout d&#8217;abord lister nos sites AD avec la commande:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;">Get<span style="color: pink;">-</span>ADReplicationSite <span style="color: pink;">-</span><span style="color: #0000FF;">filter</span> <span style="color: #000000;">&#123;</span>cn <span style="color: #FF0000;">-like</span> <span style="color: #800000;">&quot;*&quot;</span><span style="color: #000000;">&#125;</span></pre></div></div>

<p><a href="http://www.ldap389.info/wp-content/uploads/2012/01/get-adreplicationsite2.jpg" rel="lightbox[1642]"><img class="aligncenter size-medium wp-image-1650" title="get-adreplicationsite" src="http://www.ldap389.info/wp-content/uploads/2012/01/get-adreplicationsite2-300x189.jpg" alt="" width="300" height="189" /></a></p>
<p>Notre domaine est composée de deux sites <em>HQ-LDAP389</em> et <em>BRANCH-LDAP389</em>, on récupère aussi via cette commande l&#8217;<a href="http://support.microsoft.com/kb/224815">ISTG</a> de chaque site.</p>
<p>Puis nous listons les liens entre sites AD avec la commande:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;">Get<span style="color: pink;">-</span>ADReplicationSiteLink <span style="color: pink;">-</span><span style="color: #0000FF;">filter</span> <span style="color: #000000;">&#123;</span>cn <span style="color: #FF0000;">-like</span> <span style="color: #800000;">&quot;*&quot;</span><span style="color: #000000;">&#125;</span></pre></div></div>

<p><a href="http://www.ldap389.info/wp-content/uploads/2012/01/get-adreplicationsitelink1.jpg" rel="lightbox[1642]"><img class="aligncenter size-medium wp-image-1651" title="get-adreplicationsitelink" src="http://www.ldap389.info/wp-content/uploads/2012/01/get-adreplicationsitelink1-300x91.jpg" alt="" width="300" height="91" /></a></p>
<p>Le seul lien de site est celui par défaut <em>DEFAULTIPSITELINK</em>, configuré pour lancer une réplication toutes les 15 minutes entre <em>HQ-LDAP389</em> et <em>BRANCH-LDAP389</em>.</p>
<p>Finalement nous allons lister toutes les connexions de replication avec la commande:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;">Get<span style="color: pink;">-</span>ADReplicationConnection <span style="color: pink;">-</span><span style="color: #0000FF;">filter</span> <span style="color: #000000;">&#123;</span>cn <span style="color: #FF0000;">-like</span> <span style="color: #800000;">&quot;*&quot;</span><span style="color: #000000;">&#125;</span></pre></div></div>

<p><a href="http://www.ldap389.info/wp-content/uploads/2012/01/get-adreplicationconnection.jpg" rel="lightbox[1642]"><img class="aligncenter size-medium wp-image-1652" title="get-adreplicationconnection" src="http://www.ldap389.info/wp-content/uploads/2012/01/get-adreplicationconnection-300x289.jpg" alt="" width="300" height="289" /></a></p>
<p>Nous avons deux connexions: Une pour répliquer de <em>ldap389-pdce</em> vers <em>ldap389-dc2</em> et une autre pour répliquer dans le sens inverse.</p>
<p>Je vous rassure la commande <em><a href="http://technet.microsoft.com/en-us/library/cc755360(WS.10).aspx">repadmin</a></em> existe toujours dans la <em>Developer Preview</em>, ce qui n&#8217;est pas le cas de <em><a href="http://www.jackcobben.nl/?p=1659">dcpromo</a></em> entièrement remplacé par Powershell.</p>
<p><strong>Attention:</strong> Comme il s&#8217;agit d&#8217;une <em>Developer Preview</em> ces cmdlets ne sont peut être pas définitifs. Mais cela nous indique que nous pourrons gérer notre topologie Active Directory sous Windows 8 avec Powershell <img src='http://www.ldap389.info/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<div class="tweetthis" style="text-align:left;"><p> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=Windows+8%3A+G%C3%A9rer+la+replication+AD+avec+Powershell+http%3A%2F%2Fis.gd%2FelLP4h" 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/2012/01/08/windows-8-gerer-la-replication-ad-avec-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Powershell: exporter les firewall policies de vos serveurs TMG.</title>
		<link>http://www.ldap389.info/2011/12/22/powershell-tmg-exporter-firewall-policies/</link>
		<comments>http://www.ldap389.info/2011/12/22/powershell-tmg-exporter-firewall-policies/#comments</comments>
		<pubDate>Thu, 22 Dec 2011 00:17:46 +0000</pubDate>
		<dc:creator>ldap389</dc:creator>
				<category><![CDATA[scripts]]></category>
		<category><![CDATA[sécurité]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[tmg]]></category>

		<guid isPermaLink="false">http://www.ldap389.info/?p=1604</guid>
		<description><![CDATA[Nous allons voir dans ce post comment utiliser PowerShell avec TMG en utilisant l&#8217;objet COM FPC.root, pour plus de détails vous pouvez lire cet article. Le but de ce script est d&#8217;exporter au format XML les Firewall Policies de chacun de vos serveurs TMG: Pour nous connecter à chacun des serveurs TMG nous allons utiliser [...]]]></description>
			<content:encoded><![CDATA[<p>Nous allons voir dans ce post comment utiliser PowerShell avec TMG en utilisant l&#8217;objet COM <a href="http://msdn.microsoft.com/en-us/library/ms826706.aspx">FPC.root</a>, pour plus de détails vous pouvez lire <a href="http://www.isaserver.org/tutorials/Forefront-TMG-Scripting-with-VBScript-Powershell.html">cet article</a>.</p>
<p>Le but de ce script est d&#8217;exporter au format XML les <em>Firewall Policies</em> de chacun de vos serveurs TMG:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2011/12/firewallpolicies1.jpg" rel="lightbox[1604]"><img class="aligncenter size-medium wp-image-1606" title="firewallpolicies" src="http://www.ldap389.info/wp-content/uploads/2011/12/firewallpolicies1-300x169.jpg" alt="" width="300" height="169" /></a><br />
<span id="more-1604"></span><br />
Pour nous connecter à chacun des serveurs TMG nous allons utiliser la méthode <em><a href="http://msdn.microsoft.com/en-us/library/ms826310.aspx">ConnectToConfigurationStorageServer</a></em><em> . </em>Puis nous ferons appel à la collection <em><a href="http://msdn.microsoft.com/en-us/library/aa491800.aspx">FPCPolicyRules</a></em> pour parcourir les différentes règles firewall. Pour chaque serveur les informations suivantes seront affichées:</p>
<ul>
<li>Nom de la règle.</li>
<li>Si celle ci est active.</li>
<li>Type d&#8217;action: Accepter traffic (0), Rejeter le traffic (1).</li>
</ul>
<p>Ce qui donne:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2011/12/scriptresult.jpg" rel="lightbox[1604]"><img class="aligncenter size-medium wp-image-1607" title="scriptresult" src="http://www.ldap389.info/wp-content/uploads/2011/12/scriptresult-300x93.jpg" alt="" width="300" height="93" /></a></p>
<p>Chaque règle est exportée au format XML dans un fichier %NOMSERVER%_%NOMREGLE%.xml situé dans répertoire courant. Ceci grâce à la méthode <em><a href="http://msdn.microsoft.com/en-us/library/ms826700.aspx">FPC.ExportToFile</a>:</em></p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$oFPC</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> <span style="color: #008080; font-style: italic;">-comObject</span> FPC.root
<span style="color: #800080;">$cArrays</span> <span style="color: pink;">=</span> <span style="color: #800080;">$oFPC</span>.Arrays
<span style="color: #0000FF;">Foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$oArray</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$cArrays</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
    <span style="color: #800080;">$policyrules</span> <span style="color: pink;">=</span> <span style="color: #800080;">$oArray</span>.ArrayPolicy.policyrules
    <span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$policyrule</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$policyrules</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
        <span style="color: #800080;">$policyrule</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">select</span> name<span style="color: pink;">,</span>enabled<span style="color: pink;">,</span>action
        <span style="color: #800080;">$szOutFilePath</span> <span style="color: pink;">=</span> <span style="color: #800000;">'C:\'</span> <span style="color: pink;">+</span> <span style="color: #800080;">$policyrule</span>.name <span style="color: pink;">+</span> <span style="color: #800000;">'.xml'</span>
        <span style="color: #008000;">#See options for $iOptionalData at &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/aa490382.aspx&quot;&gt;http://msdn.microsoft.com/en-us/library/aa490382.aspx&lt;/a&gt;</span>
        <span style="color: #800080;">$iOptionalData</span> <span style="color: pink;">=</span>  0x00000001 <span style="color: #FF0000;">-bor</span> 0x00000002 <span style="color: #FF0000;">-bor</span> 0x00000004 <span style="color: #FF0000;">-bor</span> 0x00000008
        <span style="color: #800080;">$szPassword</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;12345678&quot;</span>
        <span style="color: #800080;">$szComment</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;&quot;</span>
        <span style="color: #800080;">$policyrule</span>.ExportToFile<span style="color: #000000;">&#40;</span><span style="color: #800080;">$szOutFilePath</span><span style="color: pink;">,</span> <span style="color: #800080;">$iOptionalData</span><span style="color: pink;">,</span> <span style="color: #800080;">$szPassword</span><span style="color: pink;">,</span> <span style="color: #800080;">$szComment</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Pour télécharger le script complet c&#8217;est ici:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2011/12/export-fw-policy.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>Changer les valeurs:</p>
<ul>
<li>$servers: noms de vos serveurs TMG.</li>
<li>$iOptionalData: Type d&#8217;export (données Radius etc&#8230;) Voir <a href="http://msdn.microsoft.com/en-us/library/aa490382.aspx">ce lien</a> pour plus détails.</li>
<li>$szPassword: Mot de passe utilisé pour exporter les données confidentielles (ex: données Radius)</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+exporter+les+firewall+policies+de+vos+serveurs+TMG.+http%3A%2F%2Fis.gd%2FSIIGy8" 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/12/22/powershell-tmg-exporter-firewall-policies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>Powershell: WSUS comparer patchs approuvés entre deux groupes</title>
		<link>http://www.ldap389.info/2011/10/31/powershell-wsus-comparer-patchs-approuves-entre-deux-groupes/</link>
		<comments>http://www.ldap389.info/2011/10/31/powershell-wsus-comparer-patchs-approuves-entre-deux-groupes/#comments</comments>
		<pubDate>Mon, 31 Oct 2011 14:31:29 +0000</pubDate>
		<dc:creator>ldap389</dc:creator>
				<category><![CDATA[scripts]]></category>
		<category><![CDATA[sécurité]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[wsus]]></category>

		<guid isPermaLink="false">http://www.ldap389.info/?p=1444</guid>
		<description><![CDATA[Ce script compare les KB approuvées entre deux groupes d&#8217;ordinateurs WSUS ce qui peut etre utile quand vous configurez un groupe de machines de test et un de production, vous pouvez lire cet article de Group Policy Central pour plus de détails sur ce type de configuration via de clients WSUS via GPO (voir chapitre Implement a WSUS [...]]]></description>
			<content:encoded><![CDATA[<p>Ce script compare les KB approuvées entre deux groupes d&#8217;ordinateurs WSUS ce qui peut etre utile quand vous configurez un groupe de machines de test et un de production, vous pouvez lire cet article de <a href="http://www.grouppolicy.biz/2011/06/best-practices-group-policy-for-wsus/">Group Policy Central</a> pour plus de détails sur ce type de configuration via de clients WSUS via GPO (voir chapitre <em>Implement a WSUS Update Test Group of Computers</em>).<br />
<span id="more-1444"></span></p>
<p>Pour connaitre le statut d&#8217;une mise à jour nous allons utiliser  l&#8217;espace de nom <em>Microsoft.UpdateServices.Administration </em>(enumeration <em><a href="http://msdn.microsoft.com/en-us/library/microsoft.updateservices.administration.updateapprovalaction(v=VS.85).aspx">UpdateApprovalAction</a>), </em>le code suivant parcoure toutes les KB et retourne son statut de validation pour l&#8217;ensemble des groupes d&#8217;ordinateurs.</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><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;">$updateScope</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">new-object</span> Microsoft.UpdateServices.Administration.UpdateScope;
<span style="color: #800080;">$updateScope</span>.UpdateApprovalActions <span style="color: pink;">=</span><span style="color: #000000;">&#91;</span>Microsoft.UpdateServices.Administration.UpdateApprovalActions<span style="color: #000000;">&#93;</span>::Install <span style="color: #FF0000;">-bor</span> <span style="color: #000000;">&#91;</span>Microsoft.UpdateServices.Administration.UpdateApprovalActions<span style="color: #000000;">&#93;</span>::Uninstall <span style="color: #FF0000;">-bor</span> <span style="color: #000000;">&#91;</span>Microsoft.UpdateServices.Administration.UpdateApprovalActions<span style="color: #000000;">&#93;</span>:: All <span style="color: #FF0000;">-bor</span> <span style="color: #000000;">&#91;</span>Microsoft.UpdateServices.Administration.UpdateApprovalActions<span style="color: #000000;">&#93;</span>::NotApproved
&nbsp;
<span style="color: #800080;">$updates</span> <span style="color: pink;">=</span> <span style="color: #800080;">$wsus</span>.GetUpdates<span style="color: #000000;">&#40;</span><span style="color: #800080;">$updateScope</span><span style="color: #000000;">&#41;</span>
&nbsp;
<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;">$update</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$updates</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</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>
&nbsp;
    <span style="color: #800080;">$status</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Pending&quot;</span>
&nbsp;
    <span style="color: #008000;">#MSDN update status:</span>
    <span style="color: #008000;">#All: Use to query all updates, regardless of their action.</span>
    <span style="color: #008000;">#Install: Client installs the update.</span>
    <span style="color: #008000;">#NotApproved :The Update will not be available for clients. This value can be used in a simple targeting ComputerTargetGroup to &quot;override&quot; a UpdateApproval made to the &quot;All Computers&quot; ComputerTargetGroup.</span>
    <span style="color: #008000;">#Uninstall: Client removes the update.</span>
&nbsp;
        <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$update</span>.GetUpdateApprovals<span style="color: #000000;">&#40;</span><span style="color: #800080;">$group</span><span style="color: #000000;">&#41;</span>.Count <span style="color: #FF0000;">-ne</span> <span style="color: #804000;">0</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span><span style="color: #800080;">$status</span> <span style="color: pink;">=</span> <span style="color: #800080;">$update</span>.GetUpdateApprovals<span style="color: #000000;">&#40;</span><span style="color: #800080;">$group</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span>.Action<span style="color: #000000;">&#125;</span>
    <span style="color: #008080; font-weight: bold;">write-host</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$update</span>.Title <span style="color: pink;">+</span> <span style="color: #800000;">';'</span> <span style="color: pink;">+</span> <span style="color: #800080;">$group</span>.Name <span style="color: pink;">+</span> <span style="color: #800000;">';'</span> <span style="color: pink;">+</span> <span style="color: #800080;">$status</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Les deux groupes de production et de test héritent du groupe &#8221;All Computers&#8221;:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2011/10/wsus-hierarchy.jpg" rel="lightbox[1444]"><img class="aligncenter size-medium wp-image-1449" title="wsus-hierarchy" src="http://www.ldap389.info/wp-content/uploads/2011/10/wsus-hierarchy-215x300.jpg" alt="" width="215" height="300" /></a></p>
<p>Sont récupérés le statut de chaque KB pour les groupes suivants:</p>
<ul>
<li>$Allstatus: Groupe WSUS &#8220;All computers&#8221;, valeur par défaut &#8220;<em>Not Approved</em>&#8220;.</li>
<li>$statusprod: Groupe WSUS comportant vos machines de production, valeur par défaut &#8220;<em>Pending</em>&#8220;, dans ce cas hérite de &#8220;All computers&#8221;.</li>
<li>$statusqualif: Groupe WSUS avec vos machines de qualification, valeur par défaut &#8220;<em>Pending</em>&#8220;, dans ce cas hérite de &#8220;All computers&#8221;.</li>
</ul>
<p>Si <em>$statusprod</em> est différent de <em>$statusqualif</em> alors le statut de chaque groupe est donné, si aucune valeur n&#8217;est renseignée pour l&#8217;un des deux groupes (<em>Pending</em>) alors le statut du groupe <em>All computers</em> est donné.</p>
<p>Pour télécharger le script comparant le statut de validation des patchs WSUS entre deux groupes c&#8217;est ici:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2011/10/compare-wsus-groups.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 script retourne un fichier .csv avec comme informations:</p>
<ul>
<li>Le Nom de la KB.</li>
<li>Le statut de validation pour le groupe de production en indiquant l&#8217;héritage de <em>All Computers</em> si besoin.</li>
<li>Le statut de validation pour le groupe de test en indiquant l&#8217;héritage de <em>All Computers</em> si besoin.</li>
<li>La classification MSRC du patch (voir cet <a href="http://msdn.microsoft.com/en-us/library/microsoft.updateservices.administration.msrcseverity(v=VS.85).aspx">article MSDN</a> pour les valeurs possibles).</li>
<li>Le bulletin de sécurité MS auquel il se rapporte.</li>
<li>Les produits auxquels cette KB s&#8217;applique.</li>
</ul>
<p>Changer les valeurs par défaut suivantes:</p>
<ul>
<li><em>$wsusserver</em>: Nom de votre serveur WSUS.</li>
<li><em>$grqualif</em>: Nom du groupe WSUS des ordinateurs de tests.</li>
<li><em>$grprod</em>: Nom du groupe WSUS des ordinateurs en production.</li>
</ul>
<p>Si vous voulez plus de scripts PowerShell sur WSUS je vous conseille ce lien du <a href="http://gallery.technet.microsoft.com/scriptcenter/site/search?f%5B0%5D.Type=RootCategory&amp;f%5B0%5D.Value=windowsupdate&amp;f%5B0%5D.Text=Windows%20Update&amp;f%5B1%5D.Type=SubCategory&amp;f%5B1%5D.Value=serverside&amp;f%5B1%5D.Text=Server-Side%20Management">technet script center</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+WSUS+comparer+patchs+approuv%C3%A9s+entre+deux+groupes+http%3A%2F%2Fis.gd%2F6zOKyB" 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/10/31/powershell-wsus-comparer-patchs-approuves-entre-deux-groupes/feed/</wfw:commentRss>
		<slash:comments>2</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: Générer un certificat SAN pour IIS 7 avec un CA Entreprise</title>
		<link>http://www.ldap389.info/2011/04/19/powershell-generer-certificat-san-iis-7-ca-entreprise-pki/</link>
		<comments>http://www.ldap389.info/2011/04/19/powershell-generer-certificat-san-iis-7-ca-entreprise-pki/#comments</comments>
		<pubDate>Tue, 19 Apr 2011 22:52:23 +0000</pubDate>
		<dc:creator>ldap389</dc:creator>
				<category><![CDATA[Public Key Infrastructure]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[sécurité]]></category>
		<category><![CDATA[certutil]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[pki]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[winrm]]></category>

		<guid isPermaLink="false">http://www.ldap389.info/?p=1115</guid>
		<description><![CDATA[Nous allons voir dans ce post comment générer automatiquement un certificat SAN pour un serveur Web IIS 7.0 à partir d&#8217;une PKI d&#8217;entreprise, ce certificat va nous permettre d&#8217;avoir plusieurs URL en HTTPS sur un même serveur Web. Pour y parvenir nous allons notamment utiliser le PSRemoting apporté par WinRM ainsi que les CmdLets IIS. Nous [...]]]></description>
			<content:encoded><![CDATA[<p>Nous allons voir dans ce post comment générer automatiquement un <a href="http://www.delantek.com/san.html">certificat SAN</a> pour un serveur Web IIS 7.0 à partir d&#8217;une PKI d&#8217;entreprise, ce certificat va nous permettre d&#8217;avoir plusieurs URL en HTTPS sur un même serveur Web. Pour y parvenir nous allons notamment utiliser le <a href="http://technet.microsoft.com/fr-fr/library/dd819498.aspx">PSRemoting</a> apporté par WinRM ainsi que les <a href="http://technet.microsoft.com/en-us/library/ee790599.aspx">CmdLets IIS</a>.</p>
<p>Nous lançons notre script à partir d&#8217;une console d&#8217;administration et devons utiliser le PSRemoting pour créer le fichier <a href="http://en.wikipedia.org/wiki/Certificate_signing_request">CSR</a> sur le serveur IIS avant de l&#8217;envoyer à l&#8217;autorité de certification, puis une fois le certificat émis le récupérer dans le magasin local du serveur Web et configurer la partie IIS.<br />
<span id="more-1115"></span><br />
Tout d&#8217;abord voyons le modèle de certificat utilisé, il est nommé dans notre cas <em>2008-Webserver</em>:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2011/04/certtemplate1.jpg" rel="lightbox[1115]"><img class="aligncenter size-medium wp-image-1119" title="certtemplate" src="http://www.ldap389.info/wp-content/uploads/2011/04/certtemplate1-300x129.jpg" alt="" width="300" height="129" /></a></p>
<p>Une fois demandé le certificat devra être approuvé par le <em>CA Manager</em>, par ailleurs les informations du certificat seront contenues dans la requête (CSR). La clef privée à une longueur minimale de 2048 bits et n&#8217;est pas exportable. Le CSR sera généré avec <em><a href="http://technet.microsoft.com/fr-fr/library/cc736326(WS.10).aspx">certreq.exe</a></em> à partir d&#8217;un fichier <em>RequestPolicy.inf. </em>Dans ce fichier, nous déclarons le <em>Subject Alternate Name</em> de notre certificat (i.e. nos multiples URL), à des endroits bien précis du fichier <em>RequestPolicy.inf</em>:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2011/04/saninf.jpg" rel="lightbox[1115]"><img class="aligncenter size-medium wp-image-1118" title="saninf" src="http://www.ldap389.info/wp-content/uploads/2011/04/saninf-300x176.jpg" alt="" width="300" height="176" /></a></p>
<p>Comme l&#8217;indique la capture d&#8217;écran ci-dessus de cet article <a href="http://technet.microsoft.com/en-us/library/ff625722(WS.10).aspx#BKMK_Security">technet</a>, les SAN seront déclarés dans la section <em>Extension</em> du fichier. Attention sur un CA d&#8217;entreprise ne jamais permettre l&#8217;obtention de certificats SAN en éditant la section <em>RequestAttributes</em> du fichier <em>RequestPolicy.inf</em>, ceci pour des raisons de sécurité, cela n&#8217;est valable que pour un CA en standalone.</p>
<p>Voyons donc à quoi va ressembler notre fichier <em>RequestPolicy.inf:</em></p>
<blockquote><p>[Version]<br />
Signature=&#8221;$Windows NT$&#8221;</p>
<p>[NewRequest]<br />
Exportable = FALSE<br />
KeyLength = 204<br />
RequestType = CMC<br />
[RequestAttributes]<br />
CertificateTemplate= 2008-WEBSERVER</p>
<p>[Extensions]<br />
2.5.29.17 = &#8220;{text}&#8221;<br />
_continue_ = &#8220;dns=webURL1.ldap389.info&amp;&#8221;<br />
_continue_ = &#8220;dns=webURL2.ldap389.fr&amp;&#8221;<br />
_continue_ = &#8220;dns=webURL3.ldap389.info&amp;&#8221;</p></blockquote>
<p>Pour lancer la génération du CSR sur le serveur IIS ($webserver) avec la commande <em>certreq -new, </em>ceci à partir de notre console nous utilisons le CmdLet <a href="http://technet.microsoft.com/fr-fr/library/dd347578.aspx">Invoke-Command</a>. A propos du PSRemoting et WinRM je vous conseille la lecture des séries d&#8217;articles de <a href="http://www.ravichaganti.com/blog/?p=1305">Ravikanth Chaganti</a>.</p>
<p>Le fichier CSR ($iisreq) doit ensuite être soumis au CA ($CAPath):</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$array</span> <span style="color: pink;">=</span> <span style="color: pink;">@</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$CAPath</span><span style="color: pink;">,</span><span style="color: #800080;">$iisreq</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$Requestforsigning</span> <span style="color: pink;">=</span> invoke<span style="color: pink;">-</span>command <span style="color: #800080;">$webserver</span> <span style="color: #000000;">&#123;</span><span style="color: #0000FF;">param</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$argarray</span><span style="color: #000000;">&#41;</span>;certreq.exe <span style="color: pink;">-</span>config <span style="color: #800080;">$argarray</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span> <span style="color: pink;">-</span>submit <span style="color: #800080;">$argarray</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#125;</span> <span style="color: #008080; font-style: italic;">-ArgumentList</span> <span style="color: #800080;">$array</span><span style="color: pink;">,</span><span style="color: #800080;">$null</span>
<span style="color: #800080;">$reqt</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Requestforsigning</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span>.replace<span style="color: #000000;">&#40;</span><span style="color: #800000;">'RequestId: '</span><span style="color: pink;">,</span><span style="color: #800000;">''</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p>L&#8217;ID de la requête est alors récupéré dans la variable <em>$reqt</em>. Il devra ensuite être validé sur la console d&#8217;administration par un CA Manager (vous <img src='http://www.ldap389.info/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  ), à l&#8217;aide de la commande <em>certutil -resubmit $reqt.</em></p>
<p>Reste ensuite à récupérer le certificat sur le serveur IIS et à l&#8217;intégrer dans le magasin local de l&#8217;ordinateur, toujours avec le CmdLet Invoke-Command:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$array</span> <span style="color: pink;">=</span> <span style="color: pink;">@</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$reqt</span><span style="color: pink;">,</span><span style="color: #800080;">$iiscrt</span><span style="color: pink;">,</span><span style="color: #800080;">$CAPath</span><span style="color: #000000;">&#41;</span>
invoke<span style="color: pink;">-</span>command <span style="color: #800080;">$webserver</span> <span style="color: pink;">-</span>scriptblock <span style="color: #000000;">&#123;</span>
 <span style="color: #0000FF;">param</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$argarray</span><span style="color: #000000;">&#41;</span>
 certreq <span style="color: pink;">-</span>config <span style="color: #800080;">$argarray</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">2</span><span style="color: #000000;">&#93;</span> <span style="color: pink;">-</span>retrieve <span style="color: #800080;">$argarray</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span> <span style="color: #800080;">$argarray</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">1</span><span style="color: #000000;">&#93;</span>
 certreq <span style="color: pink;">-</span>accept <span style="color: #800080;">$argarray</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">1</span><span style="color: #000000;">&#93;</span>
<span style="color: #000000;">&#125;</span> <span style="color: #008080; font-style: italic;">-ArgumentList</span> <span style="color: #800080;">$array</span><span style="color: pink;">,</span>$null</pre></div></div>

<p>Notre certificat SAN est alors importé dans le magasin local de notre serveur IIS:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2011/04/store.jpg" rel="lightbox[1115]"><img class="aligncenter size-medium wp-image-1124" title="store" src="http://www.ldap389.info/wp-content/uploads/2011/04/store-300x155.jpg" alt="" width="300" height="155" /></a></p>
<p>Ne reste plus qu&#8217;à configurer IIS, pour cela nous allons utiliser les <em><a href="http://technet.microsoft.com/en-us/library/ee790599.aspx">WebAdministration</a></em> CmdLets qui sont installées sur le serveur et suivre les instructions données dans ce <a href="http://stam.blogs.com/8bits/2010/09/how-to-create-a-self-signed-ssl-certificate-with-powershell.html">post</a>. Il nous faut donc tout d&#8217;abord récupérer le <a href="http://ig2600.blogspot.com/2010/01/how-do-you-thumbprint-certificate.html">thumbprint</a> du certificat à partir de notre console avec la commande <em><a href="http://blogs.technet.com/b/pki/archive/2008/10/03/disposition-values-for-certutil-view-restrict-and-some-creative-samples.aspx">certutil -view</a></em>:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$thumbprint</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>certutil <span style="color: #008080; font-style: italic;">-view</span> <span style="color: pink;">-</span>restrict <span style="color: #800000;">&quot;RequestID=$reqt&quot;</span> <span style="color: pink;">-</span>out CertificateHash csv<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>.replace<span style="color: #000000;">&#40;</span><span style="color: #800000;">' '</span><span style="color: pink;">,</span><span style="color: #800000;">''</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.replace<span style="color: #000000;">&#40;</span><span style="color: #800000;">'&quot;'</span><span style="color: pink;">,</span><span style="color: #800000;">''</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.ToUpper<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p>Puis lancer les commandes suivantes sur notre serveur IIS:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;">import<span style="color: pink;">-</span>module WebAdministration
New<span style="color: pink;">-</span>WebBinding <span style="color: #008080; font-style: italic;">-Name</span> <span style="color: #800000;">&quot;Default Web Site&quot;</span> <span style="color: pink;">-</span>IP <span style="color: #800000;">&quot;*&quot;</span> <span style="color: pink;">-</span>Port <span style="color: #804000;">443</span> <span style="color: pink;">-</span>Protocol https
<span style="color: #008080; font-weight: bold;">cd</span> IIS:\SslBindings
<span style="color: #008080; font-weight: bold;">Get-Item</span> cert:\LocalMachine\MY\<span style="color: #800080;">$thumbprint</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">new-item</span> 0.0.0.0<span style="color: pink;">!</span><span style="color: #804000;">443</span></pre></div></div>

<p>En utilisant toujours Invoke-Command (alias: icm). Voilà, votre IIS est configuré et vous pouvez appeler les URL désirées en HTTPS:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2011/04/iis.jpg" rel="lightbox[1115]"><img class="aligncenter size-medium wp-image-1125" title="iis" src="http://www.ldap389.info/wp-content/uploads/2011/04/iis-300x135.jpg" alt="" width="300" height="135" /></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/04/IIS7San.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>Ne vous reste plus qu&#8217;à changer les variables suivantes:</p>
<ul>
<li>$CAPath: Chemin de votre CA, sous la forme %FQDN_Serveur_CA%\%Nom_CA%</li>
<li>$webURL1, $webURL2, $webURL3: Les URLs à mettre dans le SAN, attention adapter le script pour un nombre d&#8217;URLs différent.</li>
<li>$CertTemplate: Nom du modèle de certificat utilisé.</li>
<li>$webserver: Nom du serveur IIS 7.</li>
</ul>
<div class="tweetthis" style="text-align:left;"><p> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=Powershell%3A+G%C3%A9n%C3%A9rer+un+certificat+SAN+pour+IIS+7+avec+un+CA+Entreprise+http%3A%2F%2Fis.gd%2FVesmga" 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/04/19/powershell-generer-certificat-san-iis-7-ca-entreprise-pki/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Powershell: configurer paramètres firewall via GPO</title>
		<link>http://www.ldap389.info/2011/03/08/powershell-configurer-firewall-gpo-2008-netsh/</link>
		<comments>http://www.ldap389.info/2011/03/08/powershell-configurer-firewall-gpo-2008-netsh/#comments</comments>
		<pubDate>Tue, 08 Mar 2011 13:06:46 +0000</pubDate>
		<dc:creator>ldap389</dc:creator>
				<category><![CDATA[gpo]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[firewall]]></category>
		<category><![CDATA[gpmc]]></category>
		<category><![CDATA[netsh]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[sysvol]]></category>

		<guid isPermaLink="false">http://www.ldap389.info/?p=1041</guid>
		<description><![CDATA[Dans ce post nous allons étudier comment mettre en place des règles pare-feu via GPO avec Windows 2008 Server. Quand vous intallez un composant Windows les ouvertures nécessaires se font automatiquement, pour certaines applications la configuration firewall ad-hoc est appliquée lors de l&#8217;installation. Par contre d&#8217;autres nécessitent l&#8217;ouverture explicite de certains ports, nous allons voir [...]]]></description>
			<content:encoded><![CDATA[<p>Dans ce post nous allons étudier comment mettre en place des règles pare-feu via GPO avec Windows 2008 Server. Quand vous intallez un composant Windows les <a href="http://msdn.microsoft.com/en-us/library/bb757002.aspx">ouvertures nécessaires </a>se font automatiquement, pour certaines applications la configuration firewall ad-hoc est appliquée lors de l&#8217;installation. Par contre d&#8217;autres nécessitent l&#8217;ouverture explicite de certains ports, nous allons voir comment importer ces paramètres dans une GPO via la commande <a href="http://technet.microsoft.com/en-us/library/cc771920(WS.10).aspx"><em>netsh advfirewall</em></a>.<br />
<span id="more-1041"></span></p>
<p>Tout d&#8217;abord cherchez les règles nécessaires au bon fonctionnement de votre application en éditant les règles firewall locales de votre serveur de tests, ces règles auront un préfixe donné (<em>$prefix=LDAP389</em> dans notre exemple). Nous exportons ces règles dans un ficher <em>wfw</em> avec la commande:</p>
<blockquote><p>netsh advfirewall export $wfwfile</p></blockquote>
<p>Nous voulons ensuite importer les règles <em>$prefix=LDAP389</em> dans une GPO ($GPONAME), ceci afin de les appliquer à un ensemble de serveurs:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2011/03/fw33.jpg" rel="lightbox[1041]"><img class="aligncenter size-medium wp-image-1050" title="fw33" src="http://www.ldap389.info/wp-content/uploads/2011/03/fw33-300x110.jpg" alt="" width="300" height="110" /></a></p>
<p>Pour importer ces paramètres vous devez utiliser <em>netsh advfirewall</em> puis vous connecter au magasin de données d&#8217;objets de stratégie de groupes. Or celui-ci n&#8217;est pas directement accessible via la commande <em>&#8220;netsh advfirewall set store gpo=domain/gpo_name&#8221;:</em></p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2011/03/fw4.jpg" rel="lightbox[1041]"><img class="aligncenter size-medium wp-image-1052" title="fw4" src="http://www.ldap389.info/wp-content/uploads/2011/03/fw4-300x214.jpg" alt="" width="300" height="214" /></a></p>
<p>Ce qui donne en PsH, merci <a href="http://www.vmdude.fr">VMdude</a> <img src='http://www.ldap389.info/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$stream</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>System.IO.StreamWriter<span style="color: #000000;">&#93;</span> <span style="color: #800080;">$netshinput</span>
<span style="color: #800080;">$stream</span>.WriteLine<span style="color: #000000;">&#40;</span><span style="color: #800000;">'advfirewall'</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$stream</span>.WriteLine<span style="color: #000000;">&#40;</span><span style="color: #800000;">'set store gpo='</span> <span style="color: pink;">+</span> <span style="color: #800080;">$domainfqdn</span> <span style="color: pink;">+</span> <span style="color: #800000;">'\'</span> <span style="color: pink;">+</span> <span style="color: #800080;">$GPONAME</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$stream</span>.WriteLine<span style="color: #000000;">&#40;</span><span style="color: #800000;">'show store'</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$stream</span>.WriteLine<span style="color: #000000;">&#40;</span><span style="color: #800000;">'import '</span> <span style="color: pink;">+</span> <span style="color: #800080;">$wfwfile</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$stream</span>.WriteLine<span style="color: #000000;">&#40;</span><span style="color: #800000;">'exit'</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$stream</span>.close<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
 <span style="color: #008080; font-weight: bold;">get-content</span> <span style="color: #800080;">$netshinput</span> <span style="color: pink;">|</span> netsh</pre></div></div>

<p>Via cette commande tous les paramètres d&#8217;ouverture firewall sont importés dans la GPO, pas seulement ceux explicitement créés, ce qui peut ralentir l&#8217;application de cette dernière. Nous allons grace au cmdlet <a href="http://technet.microsoft.com/en-us/library/ee461060.aspx">Remove-GPRegistryValue</a>, effacer les règles dont le préfixe n&#8217;est pas <em>$prefix=LDAP389 </em>et donc garder seulement les règles qui nous intéressent.</p>
<p>Avant d&#8217;effacer ces paramètres nous devons déterminer sur quel DC (<em>$bindserver</em>) la commande <em>netsh advfirewall </em>les a édités, pour cela il faut déterminer la cible active correspondant au partage SYSVOL:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2011/03/fw223.jpg" rel="lightbox[1041]"><img class="aligncenter size-medium wp-image-1048" title="fw22" src="http://www.ldap389.info/wp-content/uploads/2011/03/fw223-300x127.jpg" alt="" width="300" height="127" /></a></p>
<p>Pour avoir la valeur de <em>$bindserver</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$dfs</span> <span style="color: pink;">=</span> dfsutil cache referral
<span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$dfss</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$dfs</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: #000000;">&#40;</span><span style="color: #800080;">$dfss</span> <span style="color: #FF0000;">-like</span> <span style="color: #800000;">'*ACTIVE TARGETSET*'</span><span style="color: #000000;">&#41;</span> <span style="color: #FF0000;">-and</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$dfss</span> <span style="color: #FF0000;">-like</span> <span style="color: #800000;">'*sysvol*'</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #800080;">$bindserver</span> <span style="color: pink;">=</span> <span style="color: #800080;">$dfss</span>.split<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;\&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#125;</span></pre></div></div>

<p>Reste donc a rechercher les règles pare-feu qui ne commencent pas par <em>$prefix=LDAP389 </em>et les effacer sur DC <em>$bindserver</em>,<em> </em>ceci afin de s&#8217;affranchir des problèmes de réplication:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;"># Get GPO reg settings for FW rules</span>
<span style="color: #800080;">$gporeg</span> <span style="color: pink;">=</span> get<span style="color: pink;">-</span>GPRegistryValue <span style="color: #008080; font-style: italic;">-Name</span> <span style="color: #800080;">$GPONAME</span> <span style="color: pink;">-</span>server <span style="color: #800080;">$bindserver</span> <span style="color: #008080; font-style: italic;">-Key</span> <span style="color: #800000;">&quot;HKLM\SOFTWARE\Policies\Microsoft\WindowsFirewall\FirewallRules&quot;</span>
&nbsp;
<span style="color: #008000;"># Remove FW rules which do not match $prefix*</span>
&nbsp;
<span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$gporegs</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$gporeg</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #000000;">&#123;</span> <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$gporegs</span>.Value <span style="color: #FF0000;">-notlike</span> <span style="color: #800000;">'*Name='</span> <span style="color: pink;">+</span> <span style="color: #800080;">$prefix</span> <span style="color: pink;">+</span> <span style="color: #800000;">'*'</span><span style="color: #000000;">&#41;</span>
 <span style="color: #000000;">&#123;</span>Remove<span style="color: pink;">-</span>GPRegistryValue <span style="color: #008080; font-style: italic;">-Name</span> <span style="color: #800080;">$GPONAME</span> <span style="color: pink;">-</span>server <span style="color: #800080;">$bindserver</span> <span style="color: #008080; font-style: italic;">-key</span> <span style="color: #800000;">&quot;HKLM\SOFTWARE\Policies\Microsoft\WindowsFirewall\FirewallRules&quot;</span> <span style="color: pink;">-</span>ValueName <span style="color: #800080;">$gporegs</span>.ValueName<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Pour télécharger le script complet c&#8217;est ici:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2011/03/fw.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>Vous devez éditer les valeurs:</p>
<ul>
<li><em>$prefix</em>: Péfixe des règles FW éditées manuellement.</li>
<li><em>$GPONAME</em>: Nom de la GPO à éditer pour importer les paramètres FW.</li>
</ul>
<div class="tweetthis" style="text-align:left;"><p> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=Powershell%3A+configurer+param%C3%A8tres+firewall+via+GPO+http%3A%2F%2Fis.gd%2FidOYoG" 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/03/08/powershell-configurer-firewall-gpo-2008-netsh/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Migration de comptes: Primary group utilisateurs du domaine</title>
		<link>http://www.ldap389.info/2011/02/03/migration-de-comptes-utilisateurs-domaine-powershell-primary-group-id-513/</link>
		<comments>http://www.ldap389.info/2011/02/03/migration-de-comptes-utilisateurs-domaine-powershell-primary-group-id-513/#comments</comments>
		<pubDate>Thu, 03 Feb 2011 22:06:49 +0000</pubDate>
		<dc:creator>ldap389</dc:creator>
				<category><![CDATA[scripts]]></category>
		<category><![CDATA[troubleshooting]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[primary group]]></category>

		<guid isPermaLink="false">http://www.ldap389.info/?p=968</guid>
		<description><![CDATA[Suite à une migration de domaine AD, certains comptes migrés dans le domaine cible n&#8217;étaient pas membre du groupe utilisateurs du domaine. Afin d&#8217;identifier ces comptes nous avons utilisé la commande suivante de ActiveRoles Management Shell pour Active Directory: Get-QADUser -NotMemberof 'ldap389\domain users' &#124; export-csv domusers.csv Après avoir retiré du fichier les comptes qui ne doivent [...]]]></description>
			<content:encoded><![CDATA[<p>Suite à une migration de domaine AD, certains comptes migrés dans le domaine cible n&#8217;étaient pas membre du groupe <em>utilisateurs du domaine</em>. Afin d&#8217;identifier ces comptes nous avons utilisé la commande suivante de <a href="http://www.quest.com/powershell/activeroles-server.aspx">ActiveRoles Management Shell </a>pour Active Directory:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;">Get<span style="color: pink;">-</span>QADUser <span style="color: pink;">-</span>NotMemberof <span style="color: #800000;">'ldap389\domain users'</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">export-csv</span> domusers.csv</pre></div></div>

<p><span id="more-968"></span><br />
Après avoir retiré du fichier les comptes qui ne doivent pas être membre du groupe <em>utilisateurs du domaine</em>, comme le compte <em>guest </em>par exemple. Il nous reste à ajouter les comptes mal migrés dans le groupe <em>utilisateurs du domaine</em> et surtout définir ce groupe comme étant le groupe primaire du compte:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$csv</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">import-csv</span> domusers.csv
&nbsp;
<span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$line</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$csv</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> Add<span style="color: pink;">-</span>QADMemberOf <span style="color: #800080;">$line</span>.UserPrincipalName <span style="color: pink;">-</span><span style="color: #008080; font-weight: bold;">Group</span> <span style="color: #800000;">'ldap389\domain users'</span> ; Set<span style="color: pink;">-</span>QADUser <span style="color: #800080;">$line</span>.UserPrincipalName  <span style="color: pink;">-</span>ObjectAttributes <span style="color: pink;">@</span><span style="color: #000000;">&#123;</span>primaryGroupID<span style="color: pink;">=@</span><span style="color: #000000;">&#40;</span><span style="color: #804000;">513</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#125;</span></pre></div></div>

<p>Vous remarquez que 513 est l&#8217;ID pour définir le groupe primaire <em>utilisateurs du domaine</em>, pour une liste complète des groupes primaires connus et les IDs correspondants vous pouvez vous référer à <a href="http://support.microsoft.com/kb/243330/en-us">cette KB</a>.</p>
<div class="tweetthis" style="text-align:left;"><p> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=Migration+de+comptes%3A+Primary+group+utilisateurs+du+domaine+http%3A%2F%2Fis.gd%2FFmzH9i" 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/02/03/migration-de-comptes-utilisateurs-domaine-powershell-primary-group-id-513/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Powershell: Editer permissions sur une GPO</title>
		<link>http://www.ldap389.info/2010/11/26/powershell-editer-permission-gpo-sddl/</link>
		<comments>http://www.ldap389.info/2010/11/26/powershell-editer-permission-gpo-sddl/#comments</comments>
		<pubDate>Fri, 26 Nov 2010 00:54:50 +0000</pubDate>
		<dc:creator>ldap389</dc:creator>
				<category><![CDATA[gpo]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[sécurité]]></category>
		<category><![CDATA[gpmc]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[sddl]]></category>
		<category><![CDATA[sysvol]]></category>

		<guid isPermaLink="false">http://www.ldap389.info/?p=812</guid>
		<description><![CDATA[Afin de changer les permissions sur une GPO vous pouvez utiliser le CmdLet Set-GPPermissions disponible avec les RSAT (import-module grouppolicy). Ce CmdLet ne permet pas de mettre des permissions du type &#8220;deny&#8221; ou de remplacer directement des permissions. Nous allons voir comment remplacer des permissions à l&#8217;aide du Security Descriptor Definition Language qui est utilisé [...]]]></description>
			<content:encoded><![CDATA[<p>Afin de changer les permissions sur une GPO vous pouvez utiliser le CmdLet <a href="http://technet.microsoft.com/en-us/library/ee461038.aspx">Set-GPPermissions</a> disponible avec les RSAT (<strong>import-module grouppolicy</strong>). Ce CmdLet ne permet pas de mettre des permissions du type &#8220;deny&#8221; ou de remplacer directement des permissions. Nous allons voir comment remplacer des permissions à l&#8217;aide du <a href="http://msdn.microsoft.com/en-us/library/aa379567(VS.85).aspx">Security Descriptor Definition Language</a> qui est utilisé pour éditer les permissions de tous types d&#8217;objets (système de fichiers, objets AD&#8230;). Pour mieux appréhender ce langage et un outil pour lire le contenu d&#8217;une chaine SDDL je vous conseille cet <a href="http://blogs.dirteam.com/blogs/jorge/archive/2008/03/26/parsing-sddl-strings.aspx">article</a>.</p>
<p>L&#8217;opération de remplacement de permission sur une GPO peut servir quand un administrateur d&#8217;une OU créé une GPO, il en est alors propriétaire et ne donne pas les droits en contrôle total au groupe d&#8217;administration auquel il appartient. Sur notre domaine composé de deux sites, un par OU, nous avons deux types de GPOs:<span id="more-812"></span></p>
<ul>
<li>Les GPOs nommés &#8220;GLOBAL-*&#8221; créés par les administrateurs du domaine, et communes au SITE1 et au SITE2, elles ne sont pas modifiables par les administrateurs de site:</li>
</ul>
<p style="text-align: center;"><a href="http://www.ldap389.info/wp-content/uploads/2010/11/GLOBALGPO.jpg" rel="lightbox[812]"><img class="size-medium wp-image-818  aligncenter" title="DOMAIN_GPO" src="http://www.ldap389.info/wp-content/uploads/2010/11/GLOBALGPO-300x120.jpg" alt="" width="300" height="120" /></a></p>
<ul>
<li>Les GPOs nommés &#8220;SITEx-*&#8221; créés par les administrateurs de l&#8217;OU SITE1 ou SITE2, lors de leur création par l&#8217;administrateur de site c&#8217;est le compte utilisateur de ce dernier (par ex: <em>Site1-UserAdmin1</em> pour le SITE1) qui a les permissions sur la GPO:</li>
</ul>
<p style="text-align: center;"><a href="http://www.ldap389.info/wp-content/uploads/2010/11/SITE1GPO-NOK.jpg" rel="lightbox[812]"><img class="size-medium wp-image-819    aligncenter" title="OU-GPO-NOK" src="http://www.ldap389.info/wp-content/uploads/2010/11/SITE1GPO-NOK-300x130.jpg" alt="" width="300" height="130" /></a></p>
<p>Il faut alors remplacer les permissions de l&#8217;utilisateur <em>Site1-UserAdmin1</em> avec le groupe<em> SITE1-ADM</em> pour que tous les administrateurs puissent modifier la GPO:</p>
<p style="text-align: center;"><a href="http://www.ldap389.info/wp-content/uploads/2010/11/SITE1GPO-OK.jpg" rel="lightbox[812]"><img class="size-medium wp-image-820    aligncenter" title="SITE-GPO-OK" src="http://www.ldap389.info/wp-content/uploads/2010/11/SITE1GPO-OK-300x126.jpg" alt="" width="300" height="126" /></a></p>
<p>Le pack PowerShell utilisé sera Active Roles Management Shell for AD de <a href="http://www.quest.com/powershell/activeroles-server.aspx">Quest</a>, le but du script est de remplacer les permissions des GPOs nommés &#8220;SITE1-*&#8221; si le groupe<em> SITE1-ADM</em> n&#8217;a pas de droits d&#8217;administration sur ces dernières (critère utilisé: peut effacer la GPO).</p>
<p>Une fois les GPOs nommés &#8220;SITE1-*&#8221; trouvées nous utilisons le CmdLet <a href="http://wiki.powergui.org/index.php/Get-QADPermission">Get-QADPermission</a> pour lire les permissions sur celles ci. Si le groupe <em>SITE1-ADM</em> n&#8217;a pas de droits d&#8217;administration sur une GPO, alors nous cherchons le compte ($AdminAccount) qui a les droits &#8220;effacer&#8221; sur celle ci à l&#8217;aide de la commande:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;">Get<span style="color: pink;">-</span>QADPermission <span style="color: #800080;">$gpo</span>  <span style="color: pink;">|</span>  <span style="color: #008080; font-weight: bold;">foreach-object</span> <span style="color: #000000;">&#123;</span><span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span> <span style="color: #000080;">$_</span>.AccountName <span style="color: #FF0000;">-like</span> <span style="color: #800080;">$domain</span> <span style="color: pink;">+</span> <span style="color: #800000;">'\*'</span> <span style="color: #000000;">&#41;</span> <span style="color: #FF0000;">-and</span> <span style="color: #000000;">&#40;</span><span style="color: #000080;">$_</span>.Rights <span style="color: #FF0000;">-like</span> <span style="color: #800000;">'*delete*'</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><span style="color: #800080;">$AdminAccount</span> <span style="color: pink;">=</span> <span style="color: #000080;">$_</span>.AccountName<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#125;</span></pre></div></div>

<p>Une fois le compte $AdminAccount trouvé il nous faut récupérer son SID ($oldsid) et exporter les permissions de la GPO au format SDDL, ceci grâce au CmdLet <a href="http://wiki.powergui.org/index.php/Get-QADObjectSecurity">Get-QADObjectSecurity</a>. Puis il faut remplacer dans la chaîne SDDL le SID du compte administrateur<em> Site1-UserAdmin1</em> ($oldsid) par le SID du groupe d&#8217;administration <em>SITE1-ADM</em> ($newsid), enfin il nous faut injecter les nouvelles permissions dans la GPO grâce aux commandes suivantes, trouvées sur un post de <a href="http://bsonposh.com/archives/505">BSonPoSH</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$sddlgpc2</span> <span style="color: pink;">=</span> <span style="color: #800080;">$sddlgpc</span>.replace<span style="color: #000000;">&#40;</span><span style="color: #800080;">$oldsid</span><span style="color: pink;">,</span><span style="color: #800080;">$newsid</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$DE</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>ADSI<span style="color: #000000;">&#93;</span><span style="color: #800000;">&quot;LDAP://$gpodn&quot;</span>
<span style="color: #800080;">$DE</span>.psbase.ObjectSecurity.SetSecurityDescriptorSddlForm<span style="color: #000000;">&#40;</span><span style="color: #800080;">$sddlgpc2</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$DE</span>.psbase.commitchanges<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p>A ce stade là vous avez édité la sécurité sur une seule partie de la GPO: Le <a href="http://searchwindowsserver.techtarget.com/tip/Understanding-the-GPC-for-Group-Policy">Group Policy Container</a>. Si vous allez sur la GPO dans GPMC vous aurez le message d&#8217;erreur suivant:</p>
<p style="text-align: center;"><a href="http://www.ldap389.info/wp-content/uploads/2010/11/ERROR-GPMC1.jpg" rel="lightbox[812]"><img class="size-medium wp-image-823  aligncenter" title="ERROR-GPMC" src="http://www.ldap389.info/wp-content/uploads/2010/11/ERROR-GPMC1-300x144.jpg" alt="" width="300" height="144" /></a></p>
<p>Le remplacement de permissions est à faire aussi sur la partie SYSVOL de la GPO (répertoire identifié par son GUID) à savoir le <a href="http://searchwindowsserver.techtarget.com/tip/Knowing-key-settings-in-Group-Policy-Template-speeds-problem-resolution">Group Policy Template</a>. Cela se fait à l&#8217;aide du CmdLet <a href="http://technet.microsoft.com/en-gb/library/dd315261.aspx">Set-acl</a> et la fonction <em>SetSecurityDescriptorSddlForm</em> comme décrit dans cet <a href="http://mow001.blogspot.com/2006/05/powershell-import-and-export.html">article</a>.</p>
<p>Vous pouvez télécharger le script ici:</p>
<p><a href="http://www.ldap389.info/wp-content/uploads/2010/11/REPLACE_SDDL_GPO.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 remplacer les éléments suivants:</p>
<ul>
<li>$domain: Nom NetBios du domaine.</li>
<li>$domainFQDN: FQDN du domaine.</li>
<li>$siteadmgrp: Groupe d&#8217;administration du site.</li>
<li>$gpoprefix: Préfixe du nom des GPOs gérées par les administrateurs de site.</li>
</ul>
<p>Lancer le script <strong>REPLACE_SDDL_GPO.ps1</strong>, vous serez prompté avant le remplacement de la permission, le nom de la GPO et des comptes AD concernés sera affiché:</p>
<p style="text-align: center;"><a href="http://www.ldap389.info/wp-content/uploads/2010/11/REPLACE_SDDL_GPO.jpg" rel="lightbox[812]"><img class="size-medium wp-image-826  aligncenter" title="REPLACE_SDDL_GPO" src="http://www.ldap389.info/wp-content/uploads/2010/11/REPLACE_SDDL_GPO-300x48.jpg" alt="" width="300" 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+Editer+permissions+sur+une+GPO+http%3A%2F%2Fis.gd%2FNm6NLH" 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/11/26/powershell-editer-permission-gpo-sddl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

