<?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; DirectorySearcher</title>
	<atom:link href="http://www.indented.co.uk/index.php/tag/directorysearcher/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>Get-MailboxStatistics for Exchange 2003</title>
		<link>http://www.indented.co.uk/index.php/2009/01/22/exchange-2003-get-mailboxstatistics/</link>
		<comments>http://www.indented.co.uk/index.php/2009/01/22/exchange-2003-get-mailboxstatistics/#comments</comments>
		<pubDate>Thu, 22 Jan 2009 17:35:54 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[Exchange]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[DirectorySearcher]]></category>
		<category><![CDATA[wmi]]></category>

		<guid isPermaLink="false">http://www.highorbit.co.uk/?p=871</guid>
		<description><![CDATA[Using PowerShell to create a version of Get-MailboxStatistics for Exchange 2003. Get-MailboxStatistics returns a set of information about a mailbox for Exchange 2007. It is possible to retrieve roughly the same information using WMI for Exchange 2003. The differences The following table notes the differences in property names between Exchange 2003 and Exchange 2007. Exchange [...]


Related posts:<ol><li><a href='http://www.indented.co.uk/index.php/2010/01/22/changing-the-primary-group-with-powershell/' rel='bookmark' title='Permanent Link: Changing the Primary Group with PowerShell'>Changing the Primary Group with PowerShell</a> <small>Exactly as the title says, an example of how to...</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>Using PowerShell to create a version of Get-MailboxStatistics for Exchange 2003.<br />
<span id="more-871"></span><br />
Get-MailboxStatistics returns a set of information about a mailbox for Exchange 2007. It is possible to retrieve roughly the same information using WMI for Exchange 2003.</p>
<h3>The differences</h3>
<p>The following table notes the differences in property names between Exchange 2003 and Exchange 2007.</p>
<table>
<tr>
<th>Exchange 2007</th>
<th>Exchange 2003</th>
</tr>
<tr>
<td>AssociatedItemCount</td>
<td>AssocContentCount</td>
</tr>
<tr>
<td>DeletedItemCount</td>
<td><i>Not available</i></td>
</tr>
<tr>
<td>DisconnectDate</td>
<td>DateDiscoveredAbsentInDS</td>
</tr>
<tr>
<td>DisplayName</td>
<td>MailboxDisplayName</td>
</tr>
<tr>
<td>ItemCount</td>
<td>TotalItems</td>
</tr>
<tr>
<td>ObjectClass</td>
<td>Can be assumed to be Mailbox</td>
</tr>
<tr>
<td>StorageLimitStatus</td>
<td>StorageLimitInfo</td>
</tr>
<tr>
<td>TotalDeletedItemSize</td>
<td>DeletedMessageSizeExtended</td>
</tr>
<tr>
<td>TotalItemSize</td>
<td>Size</td>
</tr>
<tr>
<td>Database</td>
<td>Composed of Server, Storage Group and Store</td>
</tr>
<tr>
<td>DatabaseName</td>
<td>StoreName</td>
</tr>
<tr>
<td>Identity</td>
<td>MailboxGuid (repeat of above included for pipeline)</td>
</tr>
<tr>
<td>IsValid</td>
<td><i>Not available</i></td>
</tr>
<tr>
<td>OriginatingServer</td>
<td>Same as ServerName</td>
</tr>
</table>
<p>In addition to these the MailboxGuid attribute is formatted slightly differently. The MailboxGuid is enclosed in curly braces, {}, these are stripped in the code (or added when a search is being performed using a GUID)</p>
<p>No formatting is applied to the output. The output from this function can be made to look like the Exchange 2007 version of Get-MailboxStatistics by using Format-Table.</p>
<pre class="brush: powershell;">
Get-2003MailboxStatistics | Format-Table MailboxDisplayName, TotalItems, `
  StorageLimitStatus, LastLogonTime
</pre>
<p>This is the code for the function, it is not as flexible as the Exchange 2007 version with regard to pipelines, but it should accept simple input and work in much the same way otherwise.</p>
<h3>Usage examples</h3>
<pre class="brush: powershell;">
# With a Mailbox Display Name
Get-2003MailboxStatistics &quot;Chris Dent&quot;
# With a Legacy Exchange DN (&quot;-Identity&quot; itself is optional)
Get-2003MailboxStatistics -Identity &quot;/O=SomeOrg/OU=AdminGroup/CN=RECIPIENTS/CN=Someone&quot;
# For a single Mailbox Database
Get-2003MailboxStatistics -Database &quot;Mailbox Database&quot;
# For a different server
Get-2003MailboxStatistics -Server &quot;ExchangeServer02&quot;
</pre>
<h3>Get-MailboxStatistics for Exchange 2003</h3>
<pre class="brush: powershell;">
Function Get-2003MailboxStatistics {
  Param(
     [String]$Identity = &quot;&quot;,
     [String]$Server = $Env:ComputerName,
     [String]$Database = &quot;&quot;
  )

  $Filter = &quot;ServerName='$Server'&quot;
  if ($Database -ne &quot;&quot; ) {
    $Filter = &quot;$Filter AND StoreName='$Database'&quot;
  }
  if ($Identity -ne &quot;&quot;) {
    $Filter = &quot;$Filter AND (MailboxGuid='{$Identity}' OR LegacyDN='$Identity'&quot;
    $Filter = &quot;$Filter OR MailboxDisplayName='$Identity')&quot;
  }

  Get-WMIObject -ComputerName $Server `
    -Namespace &quot;root/MicrosoftExchangeV2&quot; -Class &quot;Exchange_Mailbox&quot; `
    -Filter $Filter | `
  Select-Object `
    AssocContentCount, `
    @{n='DateDiscoveredAbsentInDs';e={
      If ($_.DateDiscoveredAbsentInDs -ne $Null) {
        [Management.ManagementDateTimeConverter]::ToDateTime(`
          $_.DateDiscoveredAbsentInDs)
      }} }, `
    MailboxDisplayName, TotalItems, LastLoggedOnUserAccount, `
    @{n='LastLogonTime';e={ if ($_.LastLogonTime -ne $Null) { `
      [Management.ManagementDateTimeConverter]::ToDateTime($_.LastLogonTime)}}
    }, `
    @{n='LastLogoffTime';e={ if ($_.LastLogoffTime -ne $Null) { `
      [Management.ManagementDateTimeConverter]::ToDateTime($_.LastLogoffTime)}}
    }, `
    LegacyDN, `
    @{n='MailboxGuid';e={
      ([String]$_.MailboxGuid).ToLower() -Replace &quot;\{|\}&quot; }}, `
    @{n='ObjectClass';e={ &quot;Mailbox&quot; }}, `
    @{n='StorageLimitStatus';e={ `
      Switch ($_.StorageLimitInfo) {
        1 { &quot;BelowLimit&quot; }
        2 { &quot;IssueWarning&quot; }
        4 { &quot;ProhibitSend&quot; }
        8 { &quot;NoChecking&quot; }
        16 { &quot;MailboxDisabled&quot; } }} }, `
    DeletedMessageSize, Size, `
    @{n='Database';e={
      &quot;$($_.ServerName)\$($_.StorageGroupName)\$($_.StoreName)&quot; }}, `
    ServerName, StorageGroupName, StoreName, `
    @{n='Identity';e={ ([String]$_.MailboxGuid).ToLower() -Replace &quot;\{|\}&quot; }}
}
</pre>


<p>Related posts:<ol><li><a href='http://www.indented.co.uk/index.php/2010/01/22/changing-the-primary-group-with-powershell/' rel='bookmark' title='Permanent Link: Changing the Primary Group with PowerShell'>Changing the Primary Group with PowerShell</a> <small>Exactly as the title says, an example of how to...</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/2009/01/22/exchange-2003-get-mailboxstatistics/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
