<?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>Indented! &#187; LDAP</title>
	<atom:link href="http://www.indented.co.uk/index.php/tag/ldap/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.indented.co.uk</link>
	<description></description>
	<lastBuildDate>Fri, 02 Jul 2010 10:45:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Changing the Primary Group with PowerShell</title>
		<link>http://www.indented.co.uk/index.php/2010/01/22/changing-the-primary-group-with-powershell/</link>
		<comments>http://www.indented.co.uk/index.php/2010/01/22/changing-the-primary-group-with-powershell/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 14:48:59 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[DirectorySearcher]]></category>
		<category><![CDATA[LDAP]]></category>
		<category><![CDATA[memberOf]]></category>

		<guid isPermaLink="false">http://www.indented.co.uk/?p=1366</guid>
		<description><![CDATA[Exactly as the title says, an example of how to change the Primary Group for a set of users returned by a search with PowerShell. # The current Domain $DomainNC = ([ADSI]&#34;LDAP://RootDSE&#34;).DefaultNamingContext # The Primary Group Token for Domain Users and Guests will always be # the same value (no matter the forest). Used as [...]


Related posts:<ol><li><a href='http://www.indented.co.uk/index.php/2009/10/02/get-dsacl/' rel='bookmark' title='Permanent Link: Get-DsAcl'>Get-DsAcl</a> <small>The goal of this PowerShell function is to create a...</small></li>
<li><a href='http://www.indented.co.uk/index.php/2010/01/12/powershell-iis-and-log-settings/' rel='bookmark' title='Permanent Link: PowerShell, IIS and log settings'>PowerShell, IIS and log settings</a> <small>A function to retrieve IIS log settings from a local...</small></li>
</ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>Exactly as the title says, an example of how to change the Primary Group for a set of users returned by a search with PowerShell.<br />
<span id="more-1366"></span></p>
<pre class="brush: powershell;">
# The current Domain

$DomainNC = ([ADSI]&quot;LDAP://RootDSE&quot;).DefaultNamingContext

# The Primary Group Token for Domain Users and Guests will always be
# the same value (no matter the forest). Used as a demonstration of
# how the value can be retrieved

$OldGroup = [ADSI]&quot;LDAP://CN=Domain Users,CN=Users,$DomainNC&quot;
$OldGroup.GetInfoEx(@(&quot;primaryGroupToken&quot;), 0)
$OldGroupToken = $DomainUsers.Get(&quot;primaryGroupToken&quot;)

$NewGroup = [ADSI]&quot;LDAP://CN=Domain Guests,CN=Users,$DomainNC&quot;
$NewGroup.GetInfoEx(@(&quot;primaryGroupToken&quot;), 0)
$NewGroupToken = $DomainGuests.Get(&quot;primaryGroupToken&quot;)

# Determine which accounts will be effected by the change

$BaseOU = [ADSI]&quot;LDAP://OU=SomeWhere,$DomainNC&quot;
$LdapFilter = &quot;(&amp;(objectClass=user)(objectCategory=person)&quot; + `
  &quot;(primaryGroupId=$OldGroupToken))&quot;

# Find the users

$Searcher = New-Object DirectoryServices.DirectorySearcher($BaseOU, $LdapFilter)
$Searcher.PageSize = 1000

$Searcher.FindAll() | %{
  $User = $_.GetDirectoryEntry()

  # The user must be a member of the group first

  $NewGroup.Add($User.AdsPath)

  # Change the Primary Group

  $User.Put(&quot;primaryGroupId&quot;, $NewGroupToken)
  $User.SetInfo()

  # Then the old group can be removed

  $OldGroup.Remove($User.AdsPath)
}
</pre>


<p>Related posts:<ol><li><a href='http://www.indented.co.uk/index.php/2009/10/02/get-dsacl/' rel='bookmark' title='Permanent Link: Get-DsAcl'>Get-DsAcl</a> <small>The goal of this PowerShell function is to create a...</small></li>
<li><a href='http://www.indented.co.uk/index.php/2010/01/12/powershell-iis-and-log-settings/' rel='bookmark' title='Permanent Link: PowerShell, IIS and log settings'>PowerShell, IIS and log settings</a> <small>A function to retrieve IIS log settings from a local...</small></li>
</ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.indented.co.uk/index.php/2010/01/22/changing-the-primary-group-with-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building LDAP filters for date based attributes</title>
		<link>http://www.indented.co.uk/index.php/2009/08/27/building-ldap-filters-for-date-based-attributes/</link>
		<comments>http://www.indented.co.uk/index.php/2009/08/27/building-ldap-filters-for-date-based-attributes/#comments</comments>
		<pubDate>Thu, 27 Aug 2009 10:33:34 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[VbScript]]></category>
		<category><![CDATA[LDAP]]></category>

		<guid isPermaLink="false">http://www.highorbit.co.uk/?p=1154</guid>
		<description><![CDATA[Active Directory contains a number of attributes which hold date information. This article shows how to generate LDAP Filters for these attributes in both VbScript and PowerShell. Date attributes This LDAP Filter format can be used for the following attributes: createTimeStamp dsCorePropagationData expirationTime modifyTimeStamp whenChanged whenCreated VbScript ' The date the filter is supposed to [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>Active Directory contains a number of attributes which hold date information. This article shows how to generate LDAP Filters for these attributes in both VbScript and PowerShell.<br />
<span id="more-1154"></span></p>
<h3>Date attributes</h3>
<p>This LDAP Filter format can be used for the following attributes:</p>
<ul>
<li>createTimeStamp</li>
<li>dsCorePropagationData</li>
<li>expirationTime</li>
<li>modifyTimeStamp</li>
<li>whenChanged</li>
<li>whenCreated</li>
</ul>
<h4>VbScript</h4>
<pre class="brush: vb;">
' The date the filter is supposed to find
dtmDate = Now() - 1

arrDateParts = Array(&quot;yyyy&quot;, &quot;m&quot;, &quot;d&quot;, &quot;h&quot;, &quot;n&quot;, &quot;s&quot;)

For Each strInterval in arrDateParts
  intDatePart = DatePart(strInterval, dtmDate)
  If intDatePart &lt; 10 Then
    strDateTime = strDateTime &amp; &quot;0&quot; &amp; intDatePart
  Else
    strDateTime = strDateTime &amp; intDatePart
  End If
Next
strDateTime = strDateTime &amp; &quot;.0Z&quot;

' WhenCreated is after strDateTime. i.e. objects created since strDateTime.
WScript.Echo &quot;(whenCreated&gt;=&quot; &amp; strDateTime &amp; &quot;)&quot;
</pre>
<p>This will produce a filter like &#8220;(whenCreated>=20090826110816.0Z)&#8221;. Accuracy is based on the source date, using Date() instead of Now() would result in accuracy to a day (e.g. &#8220;(whenCreated>=20090826000000.0Z)&#8221;).</p>
<h4>PowerShell</h4>
<pre class="brush: powershell;">
# Convert yesterday to a Universal date-time string
$DateString = (Get-Date).AddDays(-1).ToString(&quot;u&quot;) -Replace &quot;-|:|\s&quot;
$DateString = $DateString -Replace &quot;Z&quot;, &quot;.0Z&quot;

Write-Host &quot;(whenCreated&gt;=$DateString)&quot;
</pre>
<p>As with the VbScript version this returns a string accurate to seconds. Accuracy can be modified by using (Get-Date).Date.AddDays(-1).</p>
<h3>Interger8 attributes</h3>
<p>An Interger8 date is represented by the number of 100-nanosecond intervals since the Microsoft epoch (01/01/1601 00:00:00). This format applies to the following attributes:</p>
<ul>
<li>accountExpires</li>
<li>badPasswordTime</li>
<li>lastLogon</li>
<li>lastLogonTimeStamp</li>
<li>lockoutTime</li>
<li>pwdLastSet</li>
</ul>
<p>Note that lastLogoff also uses this format but the value for the attribute is not maintained by Active Directory.</p>
<h4>VbScript</h4>
<pre class="brush: vb;">
' The number of days to remove from the current date
Const DAYS_TO_REMOVE = 1

dblInt8 = CDbl(DateDiff(&quot;s&quot;, CDate(&quot;01/01/1601 00:00:00&quot;), Now - DAYS_TO_REMOVE))
' Earlier than the current date. i.e. Passwords set before the generated date
WScript.Echo &quot;(&amp;(pwdLastSet&lt;=&quot; &amp; CStr(dblInt8) &amp; &quot;0000000)(!pwdLastSet=0))&quot;
</pre>
<p>This produces a filter like &#8220;(&#038;(pwdLastSet<=128957595350000000)(!pwdLastSet=0))". As with the previous filter this is accurate to seconds, that can be modified by changing the source date in the same way as before.</p>
<h4>PowerShell</h4>
<pre class="brush: powershell;">
$DaysToRemove = 1
$Int8Date = [Math]::Round(( `
  New-TimeSpan $(Get-Date(&quot;01/01/1601 00:00:00&quot;)) `
  ((Get-Date).AddDays(-$DaysToRemove))).TotalSeconds, 0)

$Int8Date = &quot;$($Int8Date.ToString())0000000&quot;

$LdapFilter = &quot;(&amp;(pwdLastSet&lt;=$Int8Date)(!pwdLastSet=0))&quot;
</pre>
<h3>accountExpires</h3>
<p>Certain attributes, such as accountExpires, have default values that can make filtering using a date string difficult.</p>
<p>The following LDAP filter can be used to return all accounts that are set to expire.</p>
<pre class="brush: powershell;">
&quot;(accountExpires&lt;=9223372032559810000)(!accountExpires=0))&quot;
</pre>
<p>Where 9223372032559810000 is the default attribute value in most cases, and 0 is the default in the rest.</p>
<p>accountExpires exhibits inconsistent behaviour depending on how it is accessed. If using iADSUser.AccountExpirationDate an account that does not expire is denoted by the date &#8220;01/01/1970 00:00:00&#8243;. This epoch date differs from the epoch used with the underlying attribute, &#8220;01/01/1601 00:00:00&#8243;.</p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.indented.co.uk/index.php/2009/08/27/building-ldap-filters-for-date-based-attributes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
