<?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>Remko Weijnen&#039;s Blog (Remko&#039;s Blog) &#187; Active Directory</title> <atom:link href="http://www.remkoweijnen.nl/blog/topics/active-directory/feed/" rel="self" type="application/rss+xml" /><link>http://www.remkoweijnen.nl/blog</link> <description>About Terminal Server, Citrix, Delphi and other stuff</description> <lastBuildDate>Tue, 31 Jan 2012 15:37:53 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.2.1</generator> <item><title>Read Maximum Password Age with PowerShell</title><link>http://www.remkoweijnen.nl/blog/2011/12/02/read-maximum-password-age-with-powershell/</link> <comments>http://www.remkoweijnen.nl/blog/2011/12/02/read-maximum-password-age-with-powershell/#comments</comments> <pubDate>Fri, 02 Dec 2011 12:47:44 +0000</pubDate> <dc:creator>Remko</dc:creator> <category><![CDATA[Active Directory]]></category> <category><![CDATA[PowerShell]]></category> <category><![CDATA[maxPwdAge]]></category><guid isPermaLink="false">http://www.remkoweijnen.nl/blog/2011/12/02/read-maximum-password-age-with-powershell/</guid> <description><![CDATA[I needed to read out the Maximum Password age with a PowerShell script in a Windows 2003 domain. Reading out the maxPwdAge attribute is a trivial task&#160; in PowerShell (I am re-using the function AdsLargeIntegerToInt64): # Read Maximum Password Age (from Domain Policy) # Read maxPwdAge attribute and convert to Int64 $maxPwdAge = AdsLargeIntegerToIn64 $Domain.maxPwdAge.Value&#40; [...]]]></description> <content:encoded><![CDATA[<p><a  href="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/12/image1.png" rel="lightbox" class="thickbox no_icon" title="image"><img style="margin: 0px 5px 0px 0px; display: inline; float: left" title="image" alt="image" align="left" src="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/12/image_thumb1.png" width="33" height="39" /></a>I needed to read out the Maximum Password age with a PowerShell script in a Windows 2003 domain.</p><p>Reading out the <a  href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms676863(v=vs.85).aspx" target="_blank">maxPwdAge</a> attribute is a trivial task&#160; in PowerShell (I am re-using the function <a  href="http://www.remkoweijnen.nl/blog/2011/12/01/convert-iadslargeinteger-to-int64-in-powershell/" target="_blank">AdsLargeIntegerToInt64</a>):</p><div class="dean_ch" style="white-space: wrap;"><span class="co1"># Read Maximum Password Age (from Domain Policy)</span><br /> <span class="co1"># Read maxPwdAge attribute and convert to Int64</span><br /> <span class="re3">$maxPwdAge</span> = AdsLargeIntegerToIn64 <span class="re3">$Domain</span>.<span class="me1">maxPwdAge</span>.<span class="me1">Value</span><span class="br0">&#40;</span></div><p>In my case this returns the value -78624000000000 but how do we interpret this?<br /></p><p><span id="more-2212"></span><p>The value is expressed in 100 nanosecond units which is the same unit as a windows <a  href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms724284(v=vs.85).aspx" target="_blank">FILETIME</a> structure uses.</p><p>Knowing that we can use the FromTicks method from the .NET <a  href="http://msdn.microsoft.com/en-us/library/system.timespan.aspx" target="_blank">TimeSpan</a> structure to convert it to the number of days:</p><div class="dean_ch" style="white-space: wrap;"><span class="re3">$maxPwdDays</span> = <span class="re4"><span class="br0">&#91;</span><span class="kw3">System</span>.<span class="me1">TimeSpan</span><span class="br0">&#93;</span></span>::<span class="me2">FromTicks</span><span class="br0">&#40;</span><span class="re4"><span class="br0">&#91;</span><span class="kw3">System</span>.<span class="me1">Math</span><span class="br0">&#93;</span></span>::<span class="me2">ABS</span><span class="br0">&#40;</span><span class="re3">$maxPwdAge</span><span class="br0">&#41;</span><span class="br0">&#41;</span>.<span class="me1">Days</span></div><p>And $maxPwdDays is 91 in my case.</p><p>Note that I am using ABS to make the value positive since maxPwdAge is always negative.</p> ]]></content:encoded> <wfw:commentRss>http://www.remkoweijnen.nl/blog/2011/12/02/read-maximum-password-age-with-powershell/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Convert IADsLargeInteger to Int64 in PowerShell</title><link>http://www.remkoweijnen.nl/blog/2011/12/01/convert-iadslargeinteger-to-int64-in-powershell/</link> <comments>http://www.remkoweijnen.nl/blog/2011/12/01/convert-iadslargeinteger-to-int64-in-powershell/#comments</comments> <pubDate>Thu, 01 Dec 2011 15:03:46 +0000</pubDate> <dc:creator>Remko</dc:creator> <category><![CDATA[Active Directory]]></category> <category><![CDATA[PowerShell]]></category> <category><![CDATA[IADsLargeInteger]]></category> <category><![CDATA[pwdLastSet]]></category><guid isPermaLink="false">http://www.remkoweijnen.nl/blog/2011/12/01/convert-iadslargeinteger-to-int64-in-powershell/</guid> <description><![CDATA[Some Active Directory attributes return an 8 byte integer in the form of an IADsLargeInteger interface. An example is the pwdLastSet attribute from a user object. Because the IADsLargeInteger object doesn&#8217;t provide type information PowerShell cannot read the HighPart and LowPart properties. So I wrote the function below to get the Int64 value of an [...]]]></description> <content:encoded><![CDATA[<p><img style="display: inline; float: right;" src="data:image/jpeg;base64,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" alt="" width="70" height="67" align="right" />Some Active Directory attributes return an 8 byte integer in the form of an <a href="file://\\LargeInteger" target="_blank">IADsLargeInteger</a> interface. An example is the pwdLastSet attribute from a user object.</p><p>Because the IADsLargeInteger object doesn&#8217;t provide type information PowerShell cannot read the HighPart and LowPart properties.</p><p>So I wrote the function below to get the Int64 value of an IADsLargeInteger:</p><p><span id="more-2200"></span></p><div class="dean_ch" style="white-space: wrap;"><span class="kw1">function</span> AdsLargeIntegerToIn64<span class="br0">&#40;</span><span class="re3">$adsLargeInteger</span><span class="br0">&#41;</span><br /> <span class="br0">&#123;</span><br /> &nbsp; &nbsp;<span class="re4"><span class="br0">&#91;</span>Int32<span class="br0">&#93;</span></span><span class="re3">$highPart</span> = <span class="re3">$adsLargeInteger</span>.<span class="me1">GetType</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">InvokeMember</span><span class="br0">&#40;</span><span class="st0">&quot;HighPart&quot;</span>, <span class="re4"><span class="br0">&#91;</span><span class="kw3">System</span>.<span class="me1">Reflection</span>.<span class="me1">BindingFlags</span><span class="br0">&#93;</span></span>::<span class="me2">GetProperty</span>, <span class="re3">$null</span>, <span class="re3">$adsLargeInteger</span>, <span class="re3">$null</span><span class="br0">&#41;</span><br /> &nbsp; &nbsp;<span class="re4"><span class="br0">&#91;</span>Int32<span class="br0">&#93;</span></span><span class="re3">$lowPart</span> &nbsp;= <span class="re3">$adsLargeInteger</span>.<span class="me1">GetType</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">InvokeMember</span><span class="br0">&#40;</span><span class="st0">&quot;LowPart&quot;</span>, &nbsp;<span class="re4"><span class="br0">&#91;</span><span class="kw3">System</span>.<span class="me1">Reflection</span>.<span class="me1">BindingFlags</span><span class="br0">&#93;</span></span>::<span class="me2">GetProperty</span>, <span class="re3">$null</span>, <span class="re3">$adsLargeInteger</span>, <span class="re3">$null</span><span class="br0">&#41;</span><br /> &nbsp; &nbsp;<span class="kw1">return</span>  <span class="re4"><span class="br0">&#91;</span>Int64<span class="br0">&#93;</span></span><span class="br0">&#40;</span><span class="st0">&quot;0x{0:x8}{1:x8}&quot;</span> <span class="re2">-f</span> <span class="re3">$highPart</span>, <span class="re3">$lowpart</span><span class="br0">&#41;</span><br /> <span class="br0">&#125;</span></div> ]]></content:encoded> <wfw:commentRss>http://www.remkoweijnen.nl/blog/2011/12/01/convert-iadslargeinteger-to-int64-in-powershell/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Settings NTFS Permissions by SID in PowerShell</title><link>http://www.remkoweijnen.nl/blog/2011/09/02/settings-ntfs-permissions-by-sid-in-powershell/</link> <comments>http://www.remkoweijnen.nl/blog/2011/09/02/settings-ntfs-permissions-by-sid-in-powershell/#comments</comments> <pubDate>Fri, 02 Sep 2011 15:21:42 +0000</pubDate> <dc:creator>Remko</dc:creator> <category><![CDATA[Active Directory]]></category> <category><![CDATA[PowerShell]]></category> <category><![CDATA[ADSI]]></category> <category><![CDATA[Security]]></category><guid isPermaLink="false">http://www.remkoweijnen.nl/blog/2011/09/02/settings-ntfs-permissions-by-sid-in-powershell/</guid> <description><![CDATA[I am currently creating a PowerShell script that creates a user with all needed Active Directory attributes, Exchange mailbox, (TS) Home- and Profile directories and so on. In such a script you can easily get failures because of Active Directory replication. Image that you create a new user account and later on you need set [...]]]></description> <content:encoded><![CDATA[<p><img style="margin: 0px 0px 0px 10px" align="right" src="http://t0.gstatic.com/images?q=tbn:ANd9GcTPzlU95MOmfR0YwGb55TQkoZENCxgxFUKqp6qqfMMaa9skPMT5gw" width="60" height="47" />I am currently creating a PowerShell script that creates a user with all needed Active Directory attributes, Exchange mailbox, (TS) Home- and Profile directories and so on.</p><p>In such a script you can easily get failures because of Active Directory replication.</p><p><span id="more-2046"></span><p><a  href="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/09/image.png" rel="lightbox" class="thickbox no_icon" title="image"><img style="background-image: none; border-right-width: 0px; margin: 0px 10px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; float: left; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" align="left" src="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/09/image_thumb.png" width="37" height="36" /></a>Image that you create a new user account and later on you need set an additional attribute. What happens if the user was created while connected to Domain Controller A and you try to set an additional attribute while connected to Domain Controller B before replication has completed?</p><p>We can prevent this easily by performing all actions on the same domain controller. In my script I query for any Domain Controller that has the Global Catalog role:</p><div class="dean_ch" style="white-space: wrap;"><span class="co1"># We will use a single domain controller for all operations to prevent</span><br /> <span class="co1"># replication issues</span><br /> <span class="re3">$DC</span> = <span class="br0">&#40;</span><span class="re0">Get-<span class="re1">DomainController</span></span> <span class="re2">-GlobalCatalog</span> <span class="br0">&#41;</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>.<span class="me1">DnsHostName</span> &nbsp; &nbsp; &nbsp;</div><p>Insert the $DC variable in your ldap binding eg:</p><div class="dean_ch" style="white-space: wrap;"><span class="re3">$User</span> = <span class="re4"><span class="br0">&#91;</span><span class="kw3">ADSI</span><span class="br0">&#93;</span></span><span class="br0">&#40;</span><span class="st0">&quot;LDAP://{0}/CN=Administrator,CN=Users,DC=Contoso,DC=com&quot;</span> <span class="re2">-f</span> <span class="re3">$DC</span><span class="br0">&#41;</span></div><p>Next problem is when you perform non ADSI operations such as setting NTFS permissions on a fileserver (eg homedirectory).</p><p>This server may not yet be able to resolve the username to it&#8217;s SID and thus the operation may fail!</p><p>We can solve this easily by giving permissions to the SID directory instead to the username. Example:</p><div class="dean_ch" style="white-space: wrap;"><span class="kw1">function</span> SetNTFSPermissionsBySid<span class="br0">&#40;</span><span class="re4"><span class="br0">&#91;</span><span class="kw3">string</span><span class="br0">&#93;</span></span><span class="re3">$directory</span>, <span class="re4"><span class="br0">&#91;</span><span class="kw3">System</span>.<span class="me1">DirectoryServices</span>.<span class="me1">DirectoryEntry</span><span class="br0">&#93;</span></span><span class="re3">$objAD</span><span class="br0">&#41;</span><br /> <span class="br0">&#123;</span><br /> &nbsp; &nbsp;<span class="co1"># Convert byte array sid to sid string</span><br /> &nbsp; &nbsp;<span class="re3">$sID</span> = <span class="re0">New-<span class="re1">Object</span></span> <span class="kw3">System</span>.<span class="me1">Security</span>.<span class="me1">Principal</span>.<span class="me1">SecurityIdentifier</span> <span class="re3">$objAD</span>.<span class="me1">objectsid</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>,<span class="nu0">0</span><br /> &nbsp; &nbsp;<br /> &nbsp; &nbsp;<span class="co1"># Inheritance This Folder, Subfolders and Files)</span><br /> &nbsp; &nbsp;<span class="re3">$inherit</span> = <span class="re4"><span class="br0">&#91;</span><span class="kw3">system</span>.<span class="me1">security</span>.<span class="me1">accesscontrol</span>.<span class="me1">InheritanceFlags</span><span class="br0">&#93;</span></span><span class="st0">&quot;ContainerInherit, ObjectInherit&quot;</span><br /> &nbsp; &nbsp;<span class="re3">$propagation</span> = <span class="re4"><span class="br0">&#91;</span><span class="kw3">system</span>.<span class="me1">security</span>.<span class="me1">accesscontrol</span>.<span class="me1">PropagationFlags</span><span class="br0">&#93;</span></span><span class="st0">&quot;None&quot;</span><br /> &nbsp; &nbsp;<br /> &nbsp; &nbsp;<span class="co1"># Retrieve the ACL</span><br /> &nbsp; &nbsp;<span class="re3">$aCL</span> = <span class="re0">Get-<span class="re1">Acl</span></span> <span class="re3">$directory</span></p><p>&nbsp; &nbsp;<span class="co1"># Create Ace</span><br /> &nbsp; &nbsp;<span class="re3">$accessRule</span> = <span class="re0">New-<span class="re1">Object</span></span> <span class="kw3">System</span>.<span class="me1">Security</span>.<span class="me1">AccessControl</span>.<span class="me1">FileSystemAccessRule</span><span class="br0">&#40;</span><span class="re3">$sID</span>, <span class="st0">&quot;Modify&quot;</span>, <span class="re3">$inherit</span>, <span class="re3">$propagation</span>, <span class="st0">&quot;Allow&quot;</span><span class="br0">&#41;</span></p><p>&nbsp; &nbsp;<span class="co1"># Add Ace to Acl&nbsp; </span><br /> &nbsp; &nbsp;<span class="re3">$aCL</span>.<span class="me1">AddAccessRule</span><span class="br0">&#40;</span><span class="re3">$accessrule</span><span class="br0">&#41;</span></p><p>&nbsp; &nbsp;<span class="co1"># Set Acl to the directory</span><br /> &nbsp; &nbsp;<span class="re0">Set-<span class="re1">Acl</span></span> <span class="re2">-aclobject</span> <span class="re3">$aCL</span> <span class="re2">-path</span> <span class="re3">$directory</span><br /> <span class="br0">&#125;</span></div> ]]></content:encoded> <wfw:commentRss>http://www.remkoweijnen.nl/blog/2011/09/02/settings-ntfs-permissions-by-sid-in-powershell/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Check if a useraccount exists with PowerShell</title><link>http://www.remkoweijnen.nl/blog/2011/09/02/check-if-a-useraccount-exists-with-powershell/</link> <comments>http://www.remkoweijnen.nl/blog/2011/09/02/check-if-a-useraccount-exists-with-powershell/#comments</comments> <pubDate>Fri, 02 Sep 2011 09:51:37 +0000</pubDate> <dc:creator>Remko</dc:creator> <category><![CDATA[Active Directory]]></category> <category><![CDATA[PowerShell]]></category><guid isPermaLink="false">http://www.remkoweijnen.nl/blog/2011/09/02/check-if-a-useraccount-exists-with-powershell/</guid> <description><![CDATA[Function below can be used to check if a given Username exists in Active Directory: function UserExists&#40;&#91;string&#93;$Username&#41; &#123; &#160; &#160;$strFilter = &#34;(&#38;(objectCategory=person)(sAMAccountName=$Username))&#34; &#160; &#160;$objDomain = New-Object System.DirectoryServices.DirectoryEntry &#160; &#160;$objSearcher = New-Object System.DirectoryServices.DirectorySearcher &#160; &#160;$objSearcher.SearchRoot = $objDomain &#160; &#160;$objSearcher.PageSize = 1000 &#160; &#160;$objSearcher.Filter = $strFilter &#160; &#160;$objSearcher.SearchScope = &#34;Subtree&#34; &#160; &#160;$colResults = $objSearcher.FindAll&#40;&#41; &#160; &#160;return &#91;bool&#93;&#40;$colResults [...]]]></description> <content:encoded><![CDATA[<p>Function below can be used to check if a given Username exists in Active Directory:<div class="dean_ch" style="white-space: wrap;"> <span class="kw1">function</span> UserExists<span class="br0">&#40;</span><span class="re4"><span class="br0">&#91;</span><span class="kw3">string</span><span class="br0">&#93;</span></span><span class="re3">$Username</span><span class="br0">&#41;</span><br /> <span class="br0">&#123;</span><br /> &nbsp; &nbsp;<span class="re3">$strFilter</span> = <span class="st0">&quot;(&amp;(objectCategory=person)(sAMAccountName=$Username))&quot;</span></p><p>&nbsp; &nbsp;<span class="re3">$objDomain</span> = <span class="re0">New-<span class="re1">Object</span></span> <span class="kw3">System</span>.<span class="me1">DirectoryServices</span>.<span class="me1">DirectoryEntry</span></p><p>&nbsp; &nbsp;<span class="re3">$objSearcher</span> = <span class="re0">New-<span class="re1">Object</span></span> <span class="kw3">System</span>.<span class="me1">DirectoryServices</span>.<span class="me1">DirectorySearcher</span><br /> &nbsp; &nbsp;<span class="re3">$objSearcher</span>.<span class="me1">SearchRoot</span> = <span class="re3">$objDomain</span><br /> &nbsp; &nbsp;<span class="re3">$objSearcher</span>.<span class="me1">PageSize</span> = <span class="nu0">1000</span><br /> &nbsp; &nbsp;<span class="re3">$objSearcher</span>.<span class="kw1">Filter</span> = <span class="re3">$strFilter</span><br /> &nbsp; &nbsp;<span class="re3">$objSearcher</span>.<span class="me1">SearchScope</span> = <span class="st0">&quot;Subtree&quot;</span></p><p>&nbsp; &nbsp;<span class="re3">$colResults</span> = <span class="re3">$objSearcher</span>.<span class="me1">FindAll</span><span class="br0">&#40;</span><span class="br0">&#41;</span><br /> &nbsp; &nbsp;<span class="kw1">return</span> <span class="re4"><span class="br0">&#91;</span><span class="kw3">bool</span><span class="br0">&#93;</span></span><span class="br0">&#40;</span><span class="re3">$colResults</span> <span class="re2">-ne</span> <span class="re3">$null</span><span class="br0">&#41;</span><br /> <span class="br0">&#125;</span><br /> &nbsp;</div> ]]></content:encoded> <wfw:commentRss>http://www.remkoweijnen.nl/blog/2011/09/02/check-if-a-useraccount-exists-with-powershell/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>AD Internals: Display RID Allocation Pools</title><link>http://www.remkoweijnen.nl/blog/2011/06/27/ad-internals-display-rid-allocation-pools/</link> <comments>http://www.remkoweijnen.nl/blog/2011/06/27/ad-internals-display-rid-allocation-pools/#comments</comments> <pubDate>Mon, 27 Jun 2011 13:37:04 +0000</pubDate> <dc:creator>Remko</dc:creator> <category><![CDATA[Active Directory]]></category> <category><![CDATA[PowerShell]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[ADSI Edit]]></category> <category><![CDATA[Internals]]></category><guid isPermaLink="false">http://www.remkoweijnen.nl/blog/?p=1950</guid> <description><![CDATA[In my previous post I wrote about a problem I had with duplicate RID Allocation pools. But how do we get more insight into these RID Allocation pools? The DCDIAG tool can display this information per domain controleler using the following syntax dcdiag /s:server /v /test:ridmanager Example output: But where in Active Directory is this [...]]]></description> <content:encoded><![CDATA[<p>In my previous post I wrote about a problem I had with duplicate RID Allocation pools.</p><p>But how do we get more insight into these RID Allocation pools?</p><p>The DCDIAG tool can display this information per domain controleler using the following syntax</p><div class="dean_ch" style="white-space: wrap;">dcdiag /s:server /v /test:ridmanager</div><p>Example output:</p><p><a  href="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/image28.png" rel="lightbox" class="thickbox no_icon" title="DCDiag Ridmanager Test"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="DCDiag Ridmanager Test" border="0" alt="DCDiag Ridmanager Test" src="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/image_thumb28.png" width="419" height="85" /></a></p><p>But where in Active Directory is this information stored and can we display it for all Domain Controllers at once for larger environments?</p><p><span id="more-1950"></span><p>Let&#8217;s start with the Active Directory part, the <em>System</em> container has an object named <em>RID Manager$:</em></p><p><a  href="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/image29.png" rel="lightbox" class="thickbox no_icon" title="ADSI Edit"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="ADSI Edit" border="0" alt="ADSI Edit System Container" src="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/image_thumb29.png" width="419" height="260" /></a></p><p>The <em>fSMORoleOwner</em> attribute holds the RID Master FSMO role owner.</p><p><em>rIDAvailablePool</em> is a Large Integer (an 8 byte value) where the lower 4 bytes&#160; are the From (Beginning of next RID pool to be allocated) and the higher 4 bytes are the To (Total number of RIDS that can be created in a domain) as displayed by <em>dcdiag</em>.</p><p>The Allocation Pools and the Next RID are kept by each server in a child object called RID Set. We can find the RID Set by querying the <em>rIDSetReferences</em> attribute which contains the LDAP path to the RID Set:</p><p><a  href="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/image30.png" rel="lightbox" class="thickbox no_icon" title="ADSI Edit"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="ADSI Edit" border="0" alt="rIDSetReferences Attribute" src="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/image_thumb30.png" width="402" height="317" /></a></p><p>The RID Set contains the other values we are looking for where <em>rIDAllocationpool </em>(the pool currently in use) and <em>rIDPreviousAllocationpool</em> (the pool that will be used next when the current pool is exhausted) are again Large Integers with a Low and a High part:</p><p><a  href="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/image31.png" rel="lightbox" class="thickbox no_icon" title="ADSI Edit"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="ADSI Edit" border="0" alt="RID Set Properties" src="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/image_thumb31.png" width="287" height="317" /></a></p><p>Now that we know where the values are stored we can write a script, I have chosen PowerShell.</p><p>First we connect to the (Default) domain and obtain the distinguishedName of the domain (DC=MyDomain, DC=local).</p><div class="dean_ch" style="white-space: wrap;"><span class="co1"># Bind to domain</span><br /> <span class="re3">$objDomain</span> = <span class="re0">New-<span class="re1">Object</span></span> <span class="kw3">System</span>.<span class="me1">DirectoryServices</span>.<span class="me1">DirectoryEntry</span><br /> <span class="re0">Write-<span class="re1">Host</span></span> <span class="st0">&quot;Domain:&quot;</span> <span class="re3">$objDomain</span>.<span class="me1">distinguishedName</span><br /> <span class="re0">Write-<span class="re1">Host</span></span> <span class="st0">&quot;Netbios name:&quot;</span> <span class="re3">$objDomain</span>.<span class="me1">name</span></div><p>Now we can open RID Manager Object:</p><div class="dean_ch" style="white-space: wrap;"><span class="co1"># Open the RID Manager Object</span><br /> <span class="re3">$strRidManager</span> = <span class="re4"><span class="br0">&#91;</span><span class="kw3">String</span><span class="br0">&#93;</span></span>::<span class="me2">Concat</span><span class="br0">&#40;</span><span class="st0">&quot;LDAP://CN=RID Manager$,CN=System,&quot;</span>, <span class="re3">$objDomain</span>.<span class="me1">distinguishedName</span><span class="br0">&#41;</span><br /> <span class="re3">$objRidManager</span> = <span class="re0">New-<span class="re1">Object</span></span> <span class="kw3">System</span>.<span class="me1">DirectoryServices</span>.<span class="me1">DirectoryEntry</span><span class="br0">&#40;</span><span class="re3">$strRidManager</span><span class="br0">&#41;</span></div><p>And query for the FSMO Role Owner:</p><div class="dean_ch" style="white-space: wrap;"><span class="co1"># Check FSMO Role Owner </span><br /> <span class="re3">$objRidMaster</span> = <span class="re0">New-<span class="re1">Object</span></span> <span class="kw3">System</span>.<span class="me1">DirectoryServices</span>.<span class="me1">DirectoryEntry</span><span class="br0">&#40;</span><span class="st0">&quot;LDAP://&quot;</span> + <span class="re3">$objRidManager</span>.<span class="me1">FsmoRoleOwner</span><span class="br0">&#41;</span><br /> <span class="re3">$objRidMaster</span> = <span class="re0">New-<span class="re1">Object</span></span> <span class="kw3">System</span>.<span class="me1">DirectoryServices</span>.<span class="me1">DirectoryEntry</span><span class="br0">&#40;</span><span class="re3">$objRidMaster</span>.<span class="me1">Parent</span><span class="br0">&#41;</span><br /> <span class="re0">Write-<span class="re1">Host</span></span> <span class="st0">&quot;RID Master:&quot;</span> <span class="re3">$objRidMaster</span>.<span class="me1">name</span></div><p>From the RID Master we read the rIDAvailablePool attribute:</p><div class="dean_ch" style="white-space: wrap;"><span class="co1"># Read Available RID Pool</span><br /> <span class="re3">$objAvailPool</span> = GetInteger8 <span class="re3">$objRidManager</span>.<span class="me1">rIDAvailablePool</span><br /> <span class="re0">Write-<span class="re1">Host</span></span> <span class="st0">&quot;RidAvailablePool: from&quot;</span> <span class="re3">$objAvailPool</span>.<span class="me1">LowPart</span> <span class="st0">&quot;to&quot;</span> <span class="re3">$objAvailPool</span>.<span class="me1">Highpart</span></div><p>GetInteger8 is a helper function to read Integer8 (Large Integer) values from Active Directory:</p><div class="dean_ch" style="white-space: wrap;"><span class="co1"># This functions read an Integer8 Value from Active Directory and returns an object</span><br /> <span class="co1"># with LowPart and Highpart properties</span><br /> <span class="kw1">function</span> GetInteger8<span class="br0">&#40;</span><span class="re4"><span class="br0">&#91;</span>Object<span class="br0">&#93;</span></span> <span class="re3">$Integer8</span><span class="br0">&#41;</span><br /> <span class="br0">&#123;</span><br /> &nbsp; &nbsp;<span class="re3">$gp</span> = <span class="re4"><span class="br0">&#91;</span>Reflection.<span class="me1">Bindingflags</span><span class="br0">&#93;</span></span>::<span class="me2">GetProperty</span><br /> &nbsp; &nbsp;<span class="re3">$objType</span> = <span class="re3">$Integer8</span>.<span class="me1">GetType</span><span class="br0">&#40;</span><span class="br0">&#41;</span><br /> &nbsp; &nbsp;<span class="re3">$objValue</span> = <span class="re3">$objType</span>.<span class="me1">InvokeMember</span><span class="br0">&#40;</span><span class="st0">&quot;Value&quot;</span>, <span class="re3">$gp</span>, <span class="re3">$null</span>, <span class="re3">$Integer8</span>, <span class="re3">$null</span><span class="br0">&#41;</span><br /> &nbsp; &nbsp;<span class="re3">$objType</span> = <span class="re3">$objValue</span>.<span class="me1">GetType</span><span class="br0">&#40;</span><span class="br0">&#41;</span><br /> &nbsp; &nbsp;<br /> &nbsp; &nbsp;<span class="re3">$return</span> = <span class="re0">New-<span class="re1">Object</span></span> <span class="re2">-TypeName</span> <span class="kw3">System</span>.<span class="me1">Object</span><br /> &nbsp; &nbsp;<br /> &nbsp; &nbsp;<span class="re3">$return</span> | <span class="re0">Add-<span class="re1">Member</span></span> <span class="re2">-MemberType</span> NoteProperty <span class="re2">-Name</span> LowPart <span class="re2">-Value</span> <span class="re3">$objType</span>.<span class="me1">InvokeMember</span><span class="br0">&#40;</span><span class="st0">&quot;LowPart&quot;</span>, <span class="re3">$gp</span>, <span class="re3">$null</span>, <span class="re3">$objValue</span>, <span class="re3">$null</span><span class="br0">&#41;</span><br /> &nbsp; &nbsp;<span class="re3">$return</span> | <span class="re0">Add-<span class="re1">Member</span></span> <span class="re2">-MemberType</span> NoteProperty <span class="re2">-Name</span> HighPart <span class="re2">-Value</span> <span class="re3">$objType</span>.<span class="me1">InvokeMember</span><span class="br0">&#40;</span><span class="st0">&quot;HighPart&quot;</span>, <span class="re3">$gp</span>, <span class="re3">$null</span>, <span class="re3">$objValue</span>, <span class="re3">$null</span><span class="br0">&#41;</span><br /> &nbsp; &nbsp;<br /> &nbsp; &nbsp;<span class="kw1">return</span> <span class="re3">$return</span><br /> <span class="br0">&#125;</span></div><p>We are going to store all RID Data in an array so we can use the Format options from PowerShell:</p><div class="dean_ch" style="white-space: wrap;"><span class="co1"># Create array to store RID Data</span><br /> <span class="re3">$RidDataSet</span> = @<span class="br0">&#40;</span><span class="br0">&#41;</span></div><p>I wrote a function to gather and return the RID Data for a Domain Controller object:</p><div class="dean_ch" style="white-space: wrap;"><span class="co1"># Note that you need to bind to the domain controller you want data from</span><br /> <span class="kw1">function</span> GetRidData<span class="br0">&#40;</span><span class="re4"><span class="br0">&#91;</span><span class="kw3">System</span>.<span class="me1">DirectoryServices</span>.<span class="me1">DirectoryEntry</span><span class="br0">&#93;</span></span> <span class="re3">$RidSet</span><span class="br0">&#41;</span><br /> <span class="br0">&#123;</span><br /> &nbsp; &nbsp;<span class="re3">$objParent</span> = <span class="re0">New-<span class="re1">Object</span></span> <span class="kw3">System</span>.<span class="me1">DirectoryServices</span>.<span class="me1">DirectoryEntry</span><span class="br0">&#40;</span><span class="re3">$RidSet</span>.<span class="me1">Parent</span><span class="br0">&#41;</span><br /> &nbsp; &nbsp;<span class="re4"><span class="br0">&#91;</span><span class="kw3">string</span><span class="br0">&#93;</span></span><span class="re3">$dcName</span> = <span class="re3">$objParent</span>.<span class="me1">Name</span><br /> &nbsp; &nbsp;<br /> &nbsp; &nbsp;<span class="re3">$return</span> = <span class="re0">New-<span class="re1">Object</span></span> <span class="re2">-TypeName</span> <span class="kw3">System</span>.<span class="me1">Object</span><br /> &nbsp; &nbsp;<span class="co1"># Domain Controller (Netbios) name</span><br /> &nbsp; &nbsp;<span class="re3">$return</span> | <span class="re0">Add-<span class="re1">Member</span></span> <span class="re2">-MemberType</span> NoteProperty <span class="re2">-Name</span> DC <span class="re2">-Value</span> <span class="re3">$dcName</span></p><p>&nbsp; &nbsp;<span class="co1"># rIDAllocationPool is a 64 bit value, the lowpart being the From and the highpart the To</span><br /> &nbsp; &nbsp;<span class="re3">$AllocPool</span> = GetInteger8 <span class="re3">$RidSet</span>.<span class="me1">rIDAllocationPool</span><br /> &nbsp; &nbsp;<span class="re3">$return</span> | <span class="re0">Add-<span class="re1">Member</span></span> <span class="re2">-MemberType</span> NoteProperty <span class="re2">-Name</span> rIDAllocationPoolFrom <span class="re2">-Value</span> <span class="re3">$AllocPool</span>.<span class="me1">LowPart</span><br /> &nbsp; &nbsp;<span class="re3">$return</span> | <span class="re0">Add-<span class="re1">Member</span></span> <span class="re2">-MemberType</span> NoteProperty <span class="re2">-Name</span> rIDAllocationPoolTo <span class="re2">-Value</span> <span class="re3">$AllocPool</span>.<span class="me1">HighPart</span><br /> &nbsp; &nbsp;<br /> &nbsp; &nbsp;<span class="co1"># rIDPreviousPool is a 64 bit value, the lowpart being the From and the highpart the To</span><br /> &nbsp; &nbsp;<span class="re3">$PrevPool</span> = GetInteger8 <span class="re3">$RidSet</span>.<span class="me1">rIDPreviousAllocationPool</span>&nbsp; &nbsp;&nbsp; &nbsp;<br /> &nbsp; &nbsp;<span class="re3">$return</span> | <span class="re0">Add-<span class="re1">Member</span></span> <span class="re2">-MemberType</span> NoteProperty <span class="re2">-Name</span> rIDPreviousAllocationPoolFrom <span class="re2">-Value</span> <span class="re3">$PrevPool</span>.<span class="me1">LowPart</span><br /> &nbsp; &nbsp;<span class="re3">$return</span> | <span class="re0">Add-<span class="re1">Member</span></span> <span class="re2">-MemberType</span> NoteProperty <span class="re2">-Name</span> rIDPreviousAllocationPoolTo <span class="re2">-Value</span> <span class="re3">$PrevPool</span>.<span class="me1">HighPart</span><br /> &nbsp; &nbsp;<br /> &nbsp; &nbsp;<span class="co1"># rIDPreviousPool is an array with a single value</span><br /> &nbsp; &nbsp;<span class="re3">$return</span> | <span class="re0">Add-<span class="re1">Member</span></span> <span class="re2">-MemberType</span> NoteProperty <span class="re2">-Name</span> rIDNextRID <span class="re2">-Value</span> <span class="re3">$RidSet</span>.<span class="me1">rIDNextRID</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><br /> &nbsp; &nbsp;<br /> &nbsp; &nbsp;<span class="kw1">return</span> <span class="re3">$return</span><br /> <span class="br0">&#125;</span></div><p>Now we can Bind to the Domain Controllers OU, enumerate all children and gather the RID Data for them:</p><div class="dean_ch" style="white-space: wrap;"><span class="co1"># Bind to the Domain Controllers OU</span><br /> <span class="re3">$objDCOU</span> = <span class="re0">New-<span class="re1">Object</span></span> <span class="kw3">System</span>.<span class="me1">DirectoryServices</span>.<span class="me1">DirectoryEntry</span><span class="br0">&#40;</span><span class="re4"><span class="br0">&#91;</span><span class="kw3">string</span><span class="br0">&#93;</span></span>::<span class="me2">Concat</span><span class="br0">&#40;</span><span class="st0">&quot;LDAP://OU=Domain Controllers,&quot;</span>, <span class="re3">$objDomain</span>.<span class="me1">distinguishedName</span><span class="br0">&#41;</span><span class="br0">&#41;</span></p><p><span class="co1"># Loop through the Domain Controllers OU</span><br /> <span class="kw1">foreach</span> <span class="br0">&#40;</span><span class="re3">$objDC</span> <span class="kw1">in</span> <span class="re3">$objDCOU</span>.<span class="me1">Children</span><span class="br0">&#41;</span><br /> <span class="br0">&#123;</span><br /> &nbsp; &nbsp;<span class="co1"># Bind to the RID Set, note that&#8217;s it&#8217;s essential to bind to the domain controller you want data from&nbsp;</span><br /> &nbsp; &nbsp;<span class="re3">$objRIDSet</span> = <span class="re0">New-<span class="re1">Object</span></span> <span class="kw3">System</span>.<span class="me1">DirectoryServices</span>.<span class="me1">DirectoryEntry</span><span class="br0">&#40;</span><span class="re4"><span class="br0">&#91;</span><span class="kw3">string</span><span class="br0">&#93;</span></span>::<span class="me2">Concat</span><span class="br0">&#40;</span><span class="st0">&quot;LDAP://&quot;</span>, <span class="re3">$objDC</span>.<span class="me1">dNSHostName</span>, <span class="st0">&quot;/&quot;</span>, <span class="re3">$objDC</span>.<span class="me1">rIDSetReferences</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br /> &nbsp; &nbsp;<br /> &nbsp; &nbsp;<span class="co1"># Add the Data to the array</span><br /> &nbsp; &nbsp;<span class="re3">$RidDataSet</span> += GetRidData <span class="re3">$objRIDSet</span><br /> <span class="br0">&#125;</span></div><p>Last step is outputting the Data:</p><div class="dean_ch" style="white-space: wrap;"><span class="co1"># Display RID Data in a nice table</span><br /> <span class="re3">$RidDataSet</span> | <span class="re0">Format-<span class="re1">Table</span></span></div><p>This is the data for my environment:</p><p><a  href="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/image32.png" rel="lightbox" class="thickbox no_icon" title="PowerShell Console"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="PowerShell Console" border="0" alt="RID Data for the Domain" src="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/image_thumb32.png" width="419" height="73" /></a></p><p>The complete script can be downloaded below.</p> <a  class="downloadlink" href="http://www.remkoweijnen.nl/blog/download/rIDump.zip" title="Version1.0 downloaded 54 times">rIDump (54)</a> ]]></content:encoded> <wfw:commentRss>http://www.remkoweijnen.nl/blog/2011/06/27/ad-internals-display-rid-allocation-pools/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>The case of the duplicate SID&#8217;s</title><link>http://www.remkoweijnen.nl/blog/2011/06/27/the-case-of-the-duplicate-sids/</link> <comments>http://www.remkoweijnen.nl/blog/2011/06/27/the-case-of-the-duplicate-sids/#comments</comments> <pubDate>Mon, 27 Jun 2011 08:04:01 +0000</pubDate> <dc:creator>Remko</dc:creator> <category><![CDATA[Active Directory]]></category> <category><![CDATA[Exchange]]></category> <category><![CDATA[NTDSUtil]]></category><guid isPermaLink="false">http://www.remkoweijnen.nl/blog/?p=1932</guid> <description><![CDATA[I encountered another interesting error during Exchange 2010 installation today. During the Organization Preparation I got the following error: The setup.log doesn&#8217;t give us much more detailed info: [06-22-2011 11:16:29.0614] [2] [ERROR] Active Directory operation failed on dc001.zorg.local. This error is not retriable. Additional information: The requested object has a non-unique identifier and cannot be [...]]]></description> <content:encoded><![CDATA[<p><a  href="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/SNAGHTML1ca684c.png?9d7bd4" class="thickbox no_icon" rel="gallery-1932" title="SNAGHTML1ca684c"><img style="margin: 0px 5px 0px 0px;" title="SNAGHTML1ca684c" src="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/SNAGHTML1ca684c_thumb.png?9d7bd4" border="0" alt="SNAGHTML1ca684c" width="49" height="49" align="left" /></a></p><p>I encountered another interesting error during Exchange 2010 installation today. During the Organization Preparation I got the following error:</p><p><a  rel="lightbox" href="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/image25.png" class="thickbox no_icon" title="Exchange Server 2010 Setup"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="Exchange Server 2010 Setup" src="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/image_thumb25.png" border="0" alt="The requested object has a non-unique identifier and cannot be retrieved.Active directory response: 0000219D: SvcErr: DSID-031A0FC0, problem 5003 (WILL_NOT_PERFORM), data 0" width="370" height="317" /></a></p><p>The setup.log doesn&#8217;t give us much more detailed info:</p><div class="dean_ch" style="white-space: wrap;">[06-22-2011 11:16:29.0614] [2] [ERROR] Active Directory operation failed on dc001.zorg.local. This error is not retriable. Additional information: The requested object has a non-unique identifier and cannot be retrieved.<br /> Active directory response: 0000219D: SvcErr: DSID-031A0FC0, problem 5003 (WILL_NOT_PERFORM), data 0</p><p>[06-22-2011 11:16:29.0630] [2] [ERROR] The server cannot handle directory requests.<br /> [06-22-2011 11:16:29.0630] [2] Ending processing initialize-ExchangeUniversalGroups<br /> [06-22-2011 11:16:29.0630] [1] The following 1 error(s) occurred during task execution:<br /> [06-22-2011 11:16:29.0630] [1] 0. &nbsp;ErrorRecord: Active Directory operation failed on dc001.zorg.local. This error is not retriable. Additional information: The requested object has a non-unique identifier and cannot be retrieved.<br /> Active directory response: 0000219D: SvcErr: DSID-031A0FC0, problem 5003 (WILL_NOT_PERFORM), data 0</p><p>[06-22-2011 11:16:29.0630] [1] 0. &nbsp;ErrorRecord: Microsoft.Exchange.Data.Directory.ADOperationException: Active Directory operation failed on dc001.zorg.local. This error is not retriable. Additional information: The requested object has a non-unique identifier and cannot be retrieved.<br /> Active directory response: 0000219D: SvcErr: DSID-031A0FC0, problem 5003 (WILL_NOT_PERFORM), data 0</div><p>I remembered from a <a  href="http://twitter.com/#!/HelgeKlein/status/79641965238562817" target="_blank">Tweet by Helge Klein</a> recently that the Active Directory schema has no mechanism for enforcing uniqueness of an attribute.</p><p><span id="more-1932"></span></p><p>My first assumption was a duplicate <a  href="http://msdn.microsoft.com/en-us/library/ms679635(v=vs.85).aspx" target="_blank">sAMAccountName</a> but I couldn&#8217;t find any evidence for that.</p><p>Then I checked for duplicate <a  href="http://en.wikipedia.org/wiki/Security_Identifier" target="_blank">SID</a>&#8216;s, you can do this via NTDSUtil:</p><p><a  rel="lightbox" href="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/image26.png" class="thickbox no_icon" title="NTSDUtil"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="NTSDUtil" src="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/image_thumb26.png" border="0" alt="check duplicate sid" width="419" height="86" /></a></p><p>NTDSUtil creates a log file in the current directory (dupsid.log) and indeed I was having duplicate SID&#8217;s:</p><div class="dean_ch" style="white-space: wrap;">The SAM database has encountered a duplicate SID. The SAM account names are:<br /> &nbsp; &nbsp;Public Folder Management and khoogeveen</p><p>The SAM database has encountered a duplicate SID. The SAM account names are:<br /> &nbsp; &nbsp;Recipient Management and azamboni</p><p>The SAM database has encountered a duplicate SID. The SAM account names are:<br /> &nbsp; &nbsp;View-Only Organization Management and jresink</p><p>The SAM database has encountered a duplicate SID. The SAM account names are:<br /> &nbsp; &nbsp;UM Management and bmelgers</p><p>The SAM database has encountered a duplicate SID. The SAM account names are:<br /> &nbsp; &nbsp;Help Desk and hvanpareren</p><p>The SAM database has encountered a duplicate SID. The SAM account names are:<br /> &nbsp; &nbsp;Records Management and gknetemann200</p><p>The SAM database has encountered a duplicate SID. The SAM account names are:<br /> &nbsp; &nbsp;Discovery Management and gknetemann224</p><p>The SAM database has encountered a duplicate SID. The SAM account names are:<br /> &nbsp; &nbsp;Server Management and gknetemann248</p><p>The SAM database has encountered a duplicate SID. The SAM account names are:<br /> &nbsp; &nbsp;Delegated Setup and gknetemann222</p><p>The SAM database has encountered a duplicate SID. The SAM account names are:<br /> &nbsp; &nbsp;Hygiene Management and gknetemann246</div><p>What made this very interesting is that the names listed here like <em>Public Folder Management</em> and <em>Recipient Management</em> are all created during Exchange 2010 installation.</p><p>This behaviour is described in <a  href="http://technet.microsoft.com/en-us/library/bb125224.aspx" target="_blank">Prepare Active Directory and Domains</a> in a little note:</p><div class="dean_ch" style="white-space: wrap;">To verify that this step completed successfully, make sure that there is a new OU in the root domain called Microsoft Exchange Security Groups. This OU should contain the following new Exchange USGs:</p><p>&nbsp;Exchange Security Groups OU:<br /> &nbsp;Exchange Organization Management<br /> &nbsp;Exchange Recipient Management<br /> &nbsp;Exchange Server Management<br /> &nbsp;Exchange View-Only Organization Management<br /> &nbsp;Exchange Public Folder Management<br /> &nbsp;Exchange UM Management<br /> &nbsp;Exchange Hygiene Management<br /> &nbsp;Exchange Records Management<br /> &nbsp;Exchange Discovery Management<br /> &nbsp;Exchange Delegated Setup<br /> &nbsp;ExchangeLegacyInterop</div><p>So what happened?</p><p>I did a P2V of 2 existing domain controller to test an AD upgrade in a Sandbox. After the AD upgrade I kept the sandbox and decided to test Exchange installation as well.</p><p>I first created a P2V of DC002, the least important domain controller, and put in online in the sandbox to test the P2V process.</p><p>Because the DC002 had the <strong>RID Master FSMO role</strong> it was possible to allocate a block (the same block) of relative ID&#8217;s in both the sandbox and the production environment.</p><p>A couple of days later I did the P2V of the other domain controller and placed it online as well. And this is where the duplicate block became a problem.</p><p>Because I am in a sandbox I could take the easy solution which is use the <strong>cleanup duplicate sid</strong> command in NTDSUtil:</p><p><a  rel="lightbox" href="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/image27.png" class="thickbox no_icon" title="image"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" src="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/image_thumb27.png" border="0" alt="image" width="419" height="92" /></a></p><p><span style="color: #ff0000;"><strong>Warning: the cleanup duplicate sid command will delete BOTH objects having the same sid!</strong></span></p><p><strong>Sidenote</strong>: It seems that the problem with the <a  href="http://www.remkoweijnen.nl/blog/2011/06/24/exchange-2010-well-known-object-entry-install-error/" target="_blank">otherWellKnownObjects attribute I described earlier</a> was actually caused by the Exchange Setup as well!</p><p><strong>My recommendations  for P2V of Domain Controllers</strong>:</p><ul><li>P2V all Domain Controllers at the same time.</li><li>If you cannot p2v all Domain Controllers at the same time, do not bring a copy online before you finished all P2V&#8217;s.</li><li>Make sure the RID Master is brought online LAST</li></ul> ]]></content:encoded> <wfw:commentRss>http://www.remkoweijnen.nl/blog/2011/06/27/the-case-of-the-duplicate-sids/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Exchange 2010 well-known object entry install error</title><link>http://www.remkoweijnen.nl/blog/2011/06/24/exchange-2010-well-known-object-entry-install-error/</link> <comments>http://www.remkoweijnen.nl/blog/2011/06/24/exchange-2010-well-known-object-entry-install-error/#comments</comments> <pubDate>Fri, 24 Jun 2011 10:52:30 +0000</pubDate> <dc:creator>Remko</dc:creator> <category><![CDATA[Active Directory]]></category> <category><![CDATA[Exchange]]></category> <category><![CDATA[PowerShell]]></category><guid isPermaLink="false">http://www.remkoweijnen.nl/blog/2011/06/24/exchange-2010-well-known-object-entry-install-error/</guid> <description><![CDATA[Today I was testing the installation of Exchange 2010 in a VMWare sandbox environment. We created the sandbox to test migration from a 2003 AD and Exchange environment to 2008 R2 with Exchange 2010. We used a P2V to get real copies of the Active Directory and the AD upgrade to 2008 R2 was already [...]]]></description> <content:encoded><![CDATA[<p><a  href="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/SNAGHTML1ca684c.png" class="thickbox no_icon" rel="gallery-1921" title="SNAGHTML1ca684c"><img style="border-width: 0px; padding-top: 0px; padding-right: 0px; padding-left: 0px; display: inline; background-image: none;" title="SNAGHTML1ca684c" src="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/SNAGHTML1ca684c_thumb.png" border="0" alt="SNAGHTML1ca684c" width="49" height="49" align="left" /></a>Today I was testing the installation of Exchange 2010 in a VMWare sandbox environment. We created the sandbox to test migration from a 2003 AD and Exchange environment to 2008 R2 with Exchange 2010.</p><p>We used a P2V to get real copies of the Active Directory and the AD upgrade to 2008 R2 was already tested.</p><p>But during the Exchange installation in the sandbox I got the following error:</p><p><a  href="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/image16.png" class="thickbox no_icon" rel="gallery-1921" title="Exchange Server 2010 Setup Error"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="Exchange Server 2010 Setup Error" src="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/image_thumb16.png" border="0" alt="The well-known object entry on the otherWellKnownObjects attribute in the container object CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=zorg,DC=local points to an invalid DN or a deleted object.  Remove the entry, and then rerun the task." width="429" height="366" /></a></p><p><span id="more-1921"></span></p><p>The setup log (located in C:\ExchangeSetupLogs) shows a little more detail:</p><div class="dean_ch" style="white-space: wrap;">[06-22-2011 11:28:58.0530] [2] [ERROR] Unexpected Error<br /> [06-22-2011 11:28:58.0530] [2] [ERROR] The well-known object entry B:32:C262A929D691B74A9E068728F8F842EA:CN=Organization Management\0ADEL:c1b94668-b67b-4231-8e5a-b11ecf5b7838,CN=Deleted Objects,DC=zorg,DC=local on the otherWellKnownObjects attribute in the container object CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=zorg,DC=local points to an invalid DN or a deleted object. &nbsp;Remove the entry, and then rerun the task.<br /> [06-22-2011 11:28:58.0546] [2] Ending processing initialize-ExchangeUniversalGroups<br /> [06-22-2011 11:28:58.0546] [1] The following 1 error(s) occurred during task execution:<br /> [06-22-2011 11:28:58.0546] [1] 0. &nbsp;ErrorRecord: The well-known object entry B:32:C262A929D691B74A9E068728F8F842EA:CN=Organization Management\0ADEL:c1b94668-b67b-4231-8e5a-b11ecf5b7838,CN=Deleted Objects,DC=zorg,DC=local on the otherWellKnownObjects attribute in the container object CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=zorg,DC=local points to an invalid DN or a deleted object. &nbsp;Remove the entry, and then rerun the task.<br /> [06-22-2011 11:28:58.0546] [1] 0. &nbsp;ErrorRecord: Microsoft.Exchange.Management.Tasks.InvalidWKObjectException: The well-known object entry B:32:C262A929D691B74A9E068728F8F842EA:CN=Organization Management\0ADEL:c1b94668-b67b-4231-8e5a-b11ecf5b7838,CN=Deleted Objects,DC=zorg,DC=local on the otherWellKnownObjects attribute in the container object CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=zorg,DC=local points to an invalid DN or a deleted object. &nbsp;Remove the entry, and then rerun the task.<br /> [06-22-2011 11:28:58.0546] [1] [ERROR] The following error was generated when &quot;$error.Clear();<br /> &nbsp; &nbsp;initialize-ExchangeUniversalGroups -DomainController $RoleDomainController -ActiveDirectorySplitPermissions $RoleActiveDirectorySplitPermissions</p><p>&quot; was run: &quot;The well-known object entry B:32:C262A929D691B74A9E068728F8F842EA:CN=Organization Management\0ADEL:c1b94668-b67b-4231-8e5a-b11ecf5b7838,CN=Deleted Objects,DC=zorg,DC=local on the otherWellKnownObjects attribute in the container object CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=zorg,DC=local points to an invalid DN or a deleted object. &nbsp;Remove the entry, and then rerun the task.&quot;.<br /> [06-22-2011 11:28:58.0546] [1] [ERROR] The well-known object entry B:32:C262A929D691B74A9E068728F8F842EA:CN=Organization Management\0ADEL:c1b94668-b67b-4231-8e5a-b11ecf5b7838,CN=Deleted Objects,DC=zorg,DC=local on the otherWellKnownObjects attribute in the container object CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=zorg,DC=local points to an invalid DN or a deleted object. &nbsp;Remove the entry, and then rerun the task.<br /> [06-22-2011 11:28:58.0546] [1] [ERROR-REFERENCE] Id=443949901 Component=</div><p>The strange thing is that it&#8217;s referring to a deleted object (since it&#8217;s in the deleted objects container). So what&#8217;s going on?</p><p>I used the ldp.exe tool to connect to the deleted objects container and inspect the Organization Management object but I couldn&#8217;t find any invalid data in it. So I was looking at the wrong place</p><p>But if you break down the error message then it&#8217;s actually very clear where you need to look:</p><p>The attribute <a  href="http://msdn.microsoft.com/en-us/library/ms679095(v=vs.85).aspx" target="_blank">otherWellKnownObjects</a> of the object <em>CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=zorg,DC=local</em> (which is a multivalued object) has a value that refers to a deleted item (<em>B:32:C262A929D691B74A9E068728F8F842EA:CN=Organization Management\0ADEL:c1b94668-b67b-4231-8e5a-b11ecf5b7838,CN=Deleted Objects,DC=zorg,DC=local</em>).</p><p>So I opened ADSI Edit and navigated to the Microsoft Exchange container:</p><p><a  rel="lightbox" href="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/image17.png" class="thickbox no_icon" title="ADSI Edit"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="ADSI Edit" src="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/image_thumb17.png" border="0" alt="CN=Microsoft Exchange, CN=Configuration" width="244" height="186" /></a></p><p>Then I looked at the properties of CN=Microsoft Exchange we can see the otherWellKnownObjects attribute:</p><p><a  href="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/image18.png" class="thickbox no_icon" rel="gallery-1921" title="CN=Microsoft Exchange Properties"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="CN=Microsoft Exchange Properties" src="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/image_thumb18.png" border="0" alt="otherWellKnownObjects Value" width="388" height="216" /></a></p><p>But unfortunately ADSI Edit cannot view or modify  this attribute:</p><p><a  href="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/image19.png" class="thickbox no_icon" rel="gallery-1921" title="ADSI Edit"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="ADSI Edit" src="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/image_thumb19.png" border="0" alt="There is no editor registered to handle this attribute type" width="380" height="148" /></a></p><p>My next attempt was <a  href="http://technet.microsoft.com/en-us/sysinternals/bb963907" target="_blank">ADExplorer</a> from SysInternals (version 1.42). Once again I navigated to the Microsoft Exchange container:</p><p><a  rel="lightbox" href="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/image20.png" class="thickbox no_icon" title="AD Explorer"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="AD Explorer" src="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/image_thumb20.png" border="0" alt="Sysinternals Active Directory Explorer" width="433" height="317" /></a></p><p>AD Explorer has no problems showing the values:</p><p><a  rel="lightbox" href="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/image21.png" class="thickbox no_icon" title="Attribute Properties"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="Attribute Properties" src="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/image_thumb21.png" border="0" alt="otherWellKnownObjects Properties" width="430" height="187" /></a></p><p>I thought I was almost there: I right clicked the wellKnownObjects Attribute then Modify and after selecting the Deleted value I clicked Remove followed by OK:</p><p><a  href="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/image22.png" class="thickbox no_icon" rel="gallery-1921" title="AD Explorer"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="AD Explorer" src="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/image_thumb22.png" border="0" alt="Modify Attribute" width="297" height="216" /></a></p><p>And this made AD Explorer hang itsself:</p><p><a  href="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/image23.png" class="thickbox no_icon" rel="gallery-1921" title="AD Explorer"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="AD Explorer" src="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/image_thumb23.png" border="0" alt="AD Explorer Hangs" width="297" height="216" /></a></p><p>Followed by Crash:</p><p><a  href="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/image24.png" class="thickbox no_icon" rel="gallery-1921" title="AD Explorer"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="AD Explorer" src="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/image_thumb24.png" border="0" alt="AD Explorer Crashes" width="295" height="133" /></a></p><p>So I had to solve it myself with the help of a PowerShell script.</p><p>First I read the the otherWellKnownObjects attribute with PowerShell (I wrote about that <a  href="http://www.remkoweijnen.nl/blog/2011/06/24/reading-the-otherwellknownobjects-attribute-with-powershell/" target="_blank">earlier</a>).</p><p>This returns a Collection that I walk backwards with a for loop, this is important when removing items in a collection during a loop (don&#8217;t shoot yourself in the foot).</p><p>For each item in the Collection I get the distinguishedName from the DNString property and if it contains &#8220;0ADEL&#8221; then I assume the object it refers to has been deleted so I remove this item from the Collection.</p><p>Finally I check if we have deleted at least one item and if so I call SetInfo() to commit the changes to Active Directory.</p><p><span style="color: #ff0000;"><strong>If you want to test the script, be sure to comment the SetInfo() call to prevent the actual deletion in your Active Directory!</strong></span></p><div class="dean_ch" style="white-space: wrap;"><span class="co1"># Get Microsoft Exchange Container</span><br /> <span class="re3">$objDE</span> = <span class="re0">New-<span class="re1">Object</span></span> <span class="kw3">System</span>.<span class="me1">DirectoryServices</span>.<span class="me1">DirectoryEntry</span><br /> <span class="re3">$ExchangeDN</span> = <span class="re4"><span class="br0">&#91;</span><span class="kw3">string</span><span class="br0">&#93;</span></span>::<span class="me2">Concat</span><span class="br0">&#40;</span><span class="st0">&quot;LDAP://CN=Microsoft Exchange,CN=Services,CN=Configuration,&quot;</span>, <span class="re3">$objDE</span>.<span class="me1">distinguishedName</span><span class="br0">&#41;</span><br /> <span class="re3">$objCN</span> = <span class="re0">New-<span class="re1">Object</span></span> <span class="kw3">System</span>.<span class="me1">DirectoryServices</span>.<span class="me1">DirectoryEntry</span><span class="br0">&#40;</span><span class="re3">$ExchangeDN</span><span class="br0">&#41;</span></p><p><span class="re3">$gp</span> = <span class="re4"><span class="br0">&#91;</span>Reflection.<span class="me1">Bindingflags</span><span class="br0">&#93;</span></span>::<span class="me2">GetProperty</span></p><p><span class="co1"># get otherWellKnownObjects Collection</span><br /> <span class="re3">$objCol</span> = <span class="re3">$objCN</span>.<span class="me1">otherWellKnownObjects</span><br /> <span class="re3">$delCount</span> = <span class="nu0">0</span></p><p><span class="co1"># Walk though the Collection backwards (always do that when deleting items)</span><br /> <span class="kw1">for</span> <span class="br0">&#40;</span><span class="re3">$i</span>=<span class="re3">$objCol</span>.<span class="me1">Count</span><span class="nu0">-1</span>; <span class="re3">$i</span> <span class="re2">-ge</span> <span class="nu0">0</span>; <span class="re3">$i</span>&#8211;<span class="br0">&#41;</span><br /> <span class="br0">&#123;</span><br /> &nbsp; &nbsp; <span class="re3">$objWKO</span> = <span class="re3">$objCol</span><span class="br0">&#91;</span><span class="re3">$i</span><span class="br0">&#93;</span><br /> &nbsp; &nbsp; <span class="re3">$objType</span> = <span class="re3">$objWKO</span>.<span class="me1">GetType</span><span class="br0">&#40;</span><span class="br0">&#41;</span><br /> &nbsp; &nbsp;<span class="co1"># Get the distinguishedName</span><br /> &nbsp; &nbsp;<span class="re3">$DNString</span> = <span class="re3">$objType</span>.<span class="me1">InvokeMember</span><span class="br0">&#40;</span><span class="st0">&quot;DNString&quot;</span>, <span class="re3">$gp</span>, <span class="re3">$null</span>, <span class="re3">$objWKO</span>, <span class="re3">$null</span><span class="br0">&#41;</span></p><p>&nbsp; &nbsp; <span class="re3">$BV</span> = <span class="re3">$objType</span>.<span class="me1">InvokeMember</span><span class="br0">&#40;</span><span class="st0">&quot;BinaryValue&quot;</span>, <span class="re3">$gp</span>, <span class="re3">$null</span>, <span class="re3">$objWKO</span>, <span class="re3">$null</span><span class="br0">&#41;</span><br /> &nbsp; &nbsp; <span class="re3">$Guid</span> = <span class="re4"><span class="br0">&#91;</span>GUID<span class="br0">&#93;</span><span class="br0">&#91;</span><span class="kw3">System</span>.<span class="me1">BitConverter</span><span class="br0">&#93;</span></span>::<span class="me2">ToString</span><span class="br0">&#40;</span><span class="re3">$BV</span><span class="br0">&#41;</span>.<span class="kw2">Replace</span><span class="br0">&#40;</span><span class="st0">&quot;-&quot;</span>, <span class="st0">&quot;&quot;</span><span class="br0">&#41;</span></p><p>&nbsp; &nbsp; <span class="re0">Write-<span class="re1">Host</span></span> <span class="st0">&quot;DNString: $DNString&quot;</span><br /> &nbsp; &nbsp; <span class="re0">Write-<span class="re1">Host</span></span> <span class="st0">&quot;Guid: $Guid&quot;</span></p><p>&nbsp; &nbsp;<span class="co1"># Check if the item was deleted</span><br /> &nbsp; &nbsp;<span class="kw1">if</span> <span class="br0">&#40;</span><span class="re3">$DNString</span>.<span class="kw2">Contains</span><span class="br0">&#40;</span><span class="st0">&quot;0ADEL&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br /> &nbsp; &nbsp; <span class="br0">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">Write-<span class="re1">Host</span></span> <span class="st0">&quot;This is a Deleted Item&quot;</span> <span class="re2">-foregroundcolor</span> Red<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1"># Remove the item (WARNING: No Confirmation asked)</span><br /> &nbsp; &nbsp;&nbsp; &nbsp;<span class="re3">$objCol</span>.<span class="me1">RemoveAt</span><span class="br0">&#40;</span><span class="re3">$i</span><span class="br0">&#41;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">Write-<span class="re1">Host</span></span> <span class="st0">&quot;Object Removed&quot;</span> <span class="re2">-foregroundcolor</span> Red<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span class="re3">$DelCount</span>++<br /> &nbsp; &nbsp; <span class="br0">&#125;</span><br /> <span class="br0">&#125;</span></p><p><span class="co1"># Did we delete something?</span><br /> <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re3">$DelCount</span> <span class="re2">-gt</span> <span class="nu0">0</span><span class="br0">&#41;</span><br /> <span class="br0">&#123;</span><br /> &nbsp; &nbsp; <span class="re0">Write-<span class="re1">Host</span></span> <span class="st0">&quot;Commiting Changes&quot;</span> <span class="re2">-foregroundcolor</span> Blue<br /> &nbsp; &nbsp; <span class="co1"># Commit changes, remove this line if you just want to test</span><br /> &nbsp; &nbsp;<span class="co1"># If you don&#8217;t commit you will not delete anything</span><br /> &nbsp; &nbsp;<span class="re3">$objCN</span>.<span class="me1">SetInfo</span><span class="br0">&#40;</span><span class="br0">&#41;</span><br /> <span class="br0">&#125;</span></div> ]]></content:encoded> <wfw:commentRss>http://www.remkoweijnen.nl/blog/2011/06/24/exchange-2010-well-known-object-entry-install-error/feed/</wfw:commentRss> <slash:comments>8</slash:comments> </item> <item><title>Reading the otherWellKnownObjects attribute with PowerShell</title><link>http://www.remkoweijnen.nl/blog/2011/06/24/reading-the-otherwellknownobjects-attribute-with-powershell/</link> <comments>http://www.remkoweijnen.nl/blog/2011/06/24/reading-the-otherwellknownobjects-attribute-with-powershell/#comments</comments> <pubDate>Fri, 24 Jun 2011 09:19:25 +0000</pubDate> <dc:creator>Remko</dc:creator> <category><![CDATA[Active Directory]]></category> <category><![CDATA[PowerShell]]></category> <category><![CDATA[otherWellKnownObjects]]></category> <category><![CDATA[Reflection]]></category><guid isPermaLink="false">http://www.remkoweijnen.nl/blog/2011/06/24/reading-the-otherwellknownobjects-attribute-with-powershell/</guid> <description><![CDATA[I wanted to read the otherWellKnownObjects attribute from an Active Directory object. In my case this was the Microsoft Exchange container in the Configuration partition: The otherWellKnownObjects attribute is of type ADSTYPE_DN_WITH_BINARY which unfortunately cannot be viewed or edited with ADSI Edit: &#160; &#160; So I wrote a script to read the values with PowerShell [...]]]></description> <content:encoded><![CDATA[<p>I wanted to read the <a  href="http://msdn.microsoft.com/en-us/library/ms679095(v=vs.85).aspx" target="_blank">otherWellKnownObjects</a> attribute from an Active Directory object.</p><p>In my case this was the Microsoft Exchange container in the Configuration partition:</p><p><a  href="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/image14.png" rel="lightbox" class="thickbox no_icon" title="image"><img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/image_thumb14.png" width="243" height="317" /></a></p><p>The otherWellKnownObjects attribute is of type ADSTYPE_DN_WITH_BINARY which unfortunately cannot be viewed or edited with ADSI Edit:</p><p><a  href="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/image15.png" rel="lightbox" class="thickbox no_icon" title="ADSI Edit"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="ADSI Edit" border="0" alt="There is no editor registered to handle this attribute type" src="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/06/image_thumb15.png" width="381" height="149" /></a>&#160;</p><p>&#160;</p><p><span id="more-1899"></span><p>So I wrote a script to read the values with PowerShell but it&#8217;s not very straightforward how to do this.</p><p>Reading the otherWellKnownObjects property returns a collection of <a  href="http://msdn.microsoft.com/en-us/library/aa705996(VS.85).aspx" target="_blank">IADsDNWithBinary</a> interfaces but this interface is unknown in PowerShell.</p><p>Using reflection we can read the values:</p><div class="dean_ch" style="white-space: wrap;"><span class="re3">$objCN</span> = <span class="re0">New-<span class="re1">Object</span></span> <span class="kw3">System</span>.<span class="me1">DirectoryServices</span>.<span class="me1">DirectoryEntry</span><span class="br0">&#40;</span><span class="st0">&quot;LDAP://CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=zorg,DC=local&quot;</span><span class="br0">&#41;</span><br /> <span class="re3">$gp</span> = <span class="re4"><span class="br0">&#91;</span>Reflection.<span class="me1">Bindingflags</span><span class="br0">&#93;</span></span>::<span class="me2">GetProperty</span></p><p><span class="kw1">foreach</span> <span class="br0">&#40;</span><span class="re3">$objWKO</span> <span class="kw1">in</span> <span class="re3">$objCN</span>.<span class="me1">otherWellKnownObjects</span><span class="br0">&#41;</span><br /> <span class="br0">&#123;</span><br /> &nbsp; &nbsp; <span class="re3">$objType</span> = <span class="re3">$objWKO</span>.<span class="me1">GetType</span><span class="br0">&#40;</span><span class="br0">&#41;</span><br /> &nbsp; &nbsp; <span class="re3">$DNString</span> = <span class="re3">$objType</span>.<span class="me1">InvokeMember</span><span class="br0">&#40;</span><span class="st0">&quot;DNString&quot;</span>, <span class="re3">$gp</span>, <span class="re3">$null</span>, <span class="re3">$objWKO</span>, <span class="re3">$null</span><span class="br0">&#41;</span><br /> &nbsp; &nbsp; <span class="re3">$BV</span> = <span class="re3">$objType</span>.<span class="me1">InvokeMember</span><span class="br0">&#40;</span><span class="st0">&quot;BinaryValue&quot;</span>, <span class="re3">$gp</span>, <span class="re3">$null</span>, <span class="re3">$objWKO</span>, <span class="re3">$null</span><span class="br0">&#41;</span><br /> &nbsp; &nbsp; <span class="re3">$Guid</span> = <span class="re4"><span class="br0">&#91;</span>GUID<span class="br0">&#93;</span><span class="br0">&#91;</span><span class="kw3">System</span>.<span class="me1">BitConverter</span><span class="br0">&#93;</span></span>::<span class="me2">ToString</span><span class="br0">&#40;</span><span class="re3">$BV</span><span class="br0">&#41;</span>.<span class="kw2">Replace</span><span class="br0">&#40;</span><span class="st0">&quot;-&quot;</span>, <span class="st0">&quot;&quot;</span><span class="br0">&#41;</span><br /> &nbsp; &nbsp; <span class="re0">Write-<span class="re1">Host</span></span> <span class="st0">&quot;DNString=$DNString&quot;</span> <span class="re2">-foregroundcolor</span> Blue<br /> &nbsp; &nbsp; <span class="re0">Write-<span class="re1">Host</span></span> <span class="st0">&quot;Guid=$Guid&quot;</span> <span class="re2">-foregroundcolor</span> Blue &nbsp; <br /> <span class="br0">&#125;</span></div> ]]></content:encoded> <wfw:commentRss>http://www.remkoweijnen.nl/blog/2011/06/24/reading-the-otherwellknownobjects-attribute-with-powershell/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Adding a hidden Exchange mailbox to Outlook</title><link>http://www.remkoweijnen.nl/blog/2011/01/25/adding-a-hidden-exchange-mailbox-to-outlook/</link> <comments>http://www.remkoweijnen.nl/blog/2011/01/25/adding-a-hidden-exchange-mailbox-to-outlook/#comments</comments> <pubDate>Tue, 25 Jan 2011 12:11:42 +0000</pubDate> <dc:creator>Remko</dc:creator> <category><![CDATA[Active Directory]]></category> <category><![CDATA[Exchange]]></category> <category><![CDATA[PowerShell]]></category> <category><![CDATA[Address]]></category> <category><![CDATA[Check]]></category> <category><![CDATA[Global]]></category> <category><![CDATA[Hidden]]></category> <category><![CDATA[List]]></category> <category><![CDATA[Names]]></category> <category><![CDATA[Outlook]]></category> <category><![CDATA[Resolve]]></category><guid isPermaLink="false">http://www.remkoweijnen.nl/blog/?p=1286</guid> <description><![CDATA[In Exchange it&#8217;s possible to hide a Mailbox from the (Global) Address List. You can do that in the Exchange System Manager: But after you have hidden a Mailbox you cannot create an Outlook profile for it (or add it as an extra mailbox). When you click Check Name in the wizard you&#8217;ll get an [...]]]></description> <content:encoded><![CDATA[<p>In Exchange it&#8217;s possible to hide a Mailbox from the (Global) Address List. You can do that in the Exchange System Manager:</p><p><a  rel="lightbox" href="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/01/image13.png" class="thickbox no_icon" title="image"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" src="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/01/image_thumb13.png" border="0" alt="image" width="207" height="244" /></a></p><p>But after you have hidden a Mailbox you cannot create an Outlook profile for it (or add it as an extra mailbox).</p><p><a  rel="lightbox" href="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/01/image14.png" class="thickbox no_icon" title="image"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" src="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/01/image_thumb14.png" border="0" alt="image" width="244" height="188" /></a></p><p>When you click Check Name in the wizard you&#8217;ll get an error:</p><p><a  rel="lightbox" href="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/01/image15.png" class="thickbox no_icon" title="image"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" src="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/01/image_thumb15.png" border="0" alt="image" width="244" height="95" /></a></p><p>The common workaround is to remove the &#8220;<em>Hide from Exchange address lists</em>&#8221; setting, create the profile (or add the Mailbox) and afterwards set it again.</p><p>Once the profile is created it all keeps working.</p><p>There is an easier solution though!</p><p><span id="more-1286"></span><br /> If you add the mailbox using the <a  title="LegacyDN Property" href="http://msdn.microsoft.com/en-us/library/aa144763(EXCHG.65).aspx" target="_blank">legacyExchangeDN</a> attribute then Outlook happily accepts.</p><p>This works because Outlook really uses this value and not the user&#8217;s accountname to connect to a Mailbox.</p><p> The Error above occurs because Outlook cannot resolve the username to the legacyExchangeDN name using the Address List.</p><p>So how do we get the user&#8217;s legacyExchangeDN?</p><p>It can be read using ADSI Edit:</p><p><a  rel="lightbox" href="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/01/image16.png" class="thickbox no_icon" title="image"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" src="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/01/image_thumb16.png" border="0" alt="image" width="421" height="339" /></a></p><p>But I prefer to read it with a script since it means less clicking.</p><p>Using PowerShell it&#8217;s also a very simple script:</p><div class="dean_ch" style="white-space: wrap;"><span class="re0">Add-<span class="re1">Type</span></span> <span class="re2">-AssemblyName</span> <span class="kw3">System</span>.<span class="me1">DirectoryServices</span>.<span class="me1">AccountManagement</span><br /> <span class="re3">$ct</span> = <span class="re4"><span class="br0">&#91;</span><span class="kw3">System</span>.<span class="me1">DirectoryServices</span>.<span class="me1">AccountManagement</span>.<span class="me1">ContextType</span><span class="br0">&#93;</span></span>::<span class="me2">Domain</span></p><p><span class="re3">$user</span> = <span class="re4"><span class="br0">&#91;</span><span class="kw3">System</span>.<span class="me1">DirectoryServices</span>.<span class="me1">AccountManagement</span>.<span class="me1">UserPrincipal</span><span class="br0">&#93;</span></span>::<span class="me2">FindByIdentity</span><span class="br0">&#40;</span><span class="re3">$ct</span>, <span class="st0">&quot;MYDOMAIN\gtest01&quot;</span><span class="br0">&#41;</span><br /> <span class="re3">$user</span>.<span class="me1">GetUnderlyingObject</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">legacyExchangeDN</span></div><p>Now we take the result, in my case:</p><div class="dean_ch" style="white-space: wrap;">/O=My Organisation/OU=DMN-ORGANISATION/cn=Recipients/cn=gtest01</div><p>Now we copy &amp; paste this into the User Name Edit:</p><p><a  rel="lightbox" href="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/01/image17.png" class="thickbox no_icon" title="image"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" src="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/01/image_thumb17.png" border="0" alt="image" width="244" height="188" /></a></p><p>And Outlook will resolve it to the username <img class="wlEmoticon wlEmoticon-openmouthedsmile" style="border-style: none;" src="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/01/wlEmoticon-openmouthedsmile.png" alt="Open-mouthed smile" /></p><p><a  rel="lightbox" href="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/01/image18.png" class="thickbox no_icon" title="image"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" src="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/01/image_thumb18.png" border="0" alt="image" width="244" height="188" /></a></p><p>The same procedure can be used if you want to Add a Hidden Mailbox as Additional Mailbox:</p><p><a  rel="lightbox" href="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/01/image19.png" class="thickbox no_icon" title="image"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" src="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/01/image_thumb19.png" border="0" alt="image" width="198" height="244" /></a></p> ]]></content:encoded> <wfw:commentRss>http://www.remkoweijnen.nl/blog/2011/01/25/adding-a-hidden-exchange-mailbox-to-outlook/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Recursive Groups #2</title><link>http://www.remkoweijnen.nl/blog/2011/01/18/recursive-groups-2/</link> <comments>http://www.remkoweijnen.nl/blog/2011/01/18/recursive-groups-2/#comments</comments> <pubDate>Tue, 18 Jan 2011 18:51:15 +0000</pubDate> <dc:creator>Remko</dc:creator> <category><![CDATA[Active Directory]]></category> <category><![CDATA[PowerShell]]></category><guid isPermaLink="false">http://www.remkoweijnen.nl/blog/?p=1234</guid> <description><![CDATA[In my previous post I explained how to get the recursive group membership with a very simple Powershell Script. Commenter Michel thought that the script only tested one level deep but it doesn&#8217;t. But let&#8217;s prove that! Create 3 Global Groups in your Active Directory and name them Level1, 2 and 3: Make Level3 a [...]]]></description> <content:encoded><![CDATA[<p>In my <a  href="http://www.remkoweijnen.nl/blog/2011/01/18/recursive-group-membership-in-powershell/">previous post</a> I explained how to get the recursive group membership with a very simple Powershell Script.</p><p>Commenter Michel thought that the script only tested one level deep but it doesn&#8217;t.</p><p>But let&#8217;s prove that!</p><p>Create 3 Global Groups in your Active Directory and name them Level1, 2 and 3:</p><p><a  rel="lightbox" href="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/01/image2.png" class="thickbox no_icon" title="image"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/01/image_thumb2.png" border="0" alt="image" width="244" height="48" /></a></p><p>Make Level3 a Member of Level 2 and make Level a member of Level 1 and finally add an account to the Level 3 group:</p><p><a  rel="lightbox" href="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/01/image3.png" class="thickbox no_icon" title="image"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/01/image_thumb3.png" border="0" alt="image" width="244" height="81" /></a></p><p><a  rel="lightbox" href="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/01/image4.png" class="thickbox no_icon" title="image"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/01/image_thumb4.png" border="0" alt="image" width="244" height="77" /></a></p><p><a  rel="lightbox" href="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/01/image5.png" class="thickbox no_icon" title="image"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/01/image_thumb5.png" border="0" alt="image" width="244" height="79" /></a></p><p><span id="more-1234"></span>Now run the script and the output should include all 3 groups:</p><div class="dean_ch" style="white-space: wrap;"><span class="re0">Add-<span class="re1">Type</span></span> <span class="re2">-AssemblyName</span> <span class="kw3">System</span>.<span class="me1">DirectoryServices</span>.<span class="me1">AccountManagement</span><br /> <span class="re3">$ct</span> = <span class="re4"><span class="br0">&#91;</span><span class="kw3">System</span>.<span class="me1">DirectoryServices</span>.<span class="me1">AccountManagement</span>.<span class="me1">ContextType</span><span class="br0">&#93;</span></span>::<span class="me2">Domain</span></p><p><span class="re3">$user</span> = <span class="re4"><span class="br0">&#91;</span><span class="kw3">System</span>.<span class="me1">DirectoryServices</span>.<span class="me1">AccountManagement</span>.<span class="me1">UserPrincipal</span><span class="br0">&#93;</span></span>::<span class="me2">Current</span><br /> <span class="re3">$groups</span> = <span class="re3">$user</span>.<span class="me1">GetAuthorizationGroups</span><span class="br0">&#40;</span><span class="br0">&#41;</span> | <span class="kw4">where</span> <span class="br0">&#123;</span><span class="re3">$_</span> <span class="re2">-like</span> <span class="st0">&quot;G_LEVEL*&quot;</span><span class="br0">&#125;</span> | <span class="kw4">select</span> SamAccountName<br /> <span class="kw1">foreach</span> <span class="br0">&#40;</span><span class="re3">$group</span> <span class="kw1">in</span> <span class="re3">$groups</span><span class="br0">&#41;</span><br /> <span class="br0">&#123;</span><br /> &nbsp; &nbsp;<span class="re3">$group</span><br /> <span class="br0">&#125;</span></div><p>And the Output:</p><p><a  rel="lightbox" href="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/01/image6.png" class="thickbox no_icon" title="image"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://www.remkoweijnen.nl/blog/wp-content/uploads/2011/01/image_thumb6.png" border="0" alt="image" width="219" height="140" /></a></p> ]]></content:encoded> <wfw:commentRss>http://www.remkoweijnen.nl/blog/2011/01/18/recursive-groups-2/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
