title: Error with Get-ADUser: Invalid enumeration context
body: <p>I posted this question the other day
  <a href="https://stackoverflow.com/questions/30856287/extract-e-mail-from-grouped-objects/30856711?noredirect=1#comment49758538_30856711">Extract e-mail from grouped objects</a></p>
  
  <p>
  
  <pre><code>$OuUser = @{}
  
  $OuUser = Get-AdUser -Properties * -Filter * -SearchBase "domain"   
  
  $Duplicates = $OuUser | Select samaccountname, mail,UserPrincipalName |
      Group-Object Mail | Where{$_.Count -gt 1}
  
  $Duplicates | Select Name,Count,@{l='Accounts';e={($_.Group|Select -Expand samaccountname) -join ';'}} | 
      Export-CSV E:\Damo\Duplicates.csv -NoTypeInfo
  </code></pre>
  
  <p>The code works on one domain it works fine, testing it against a small set of users in a OU.</p>
  
  <p>When testing on the domain I want to test against, which has a lot of users in it this code fails. The OU has email address in it which are not of an e-mail format. It points towards Get-ADUser for the error.</p>
  
  <pre><code>Get-ADUser : The server has returned the following error: invalid enumeration c
  ontext.
  At C:\scripts\CountEmailsDup.ps1:4 char:21
  + $OuUser = Get-AdUser &lt;&lt;&lt;&lt;  -Properties * -Filter * -SearchBase 'ou=external,o
  u=user accounts,dc=bizdir,dc=nzpost,dc=co,dc=nz' -SearchScope OneLevel
      + CategoryInfo          : NotSpecified: (:) [Get-ADUser], ADException
      + FullyQualifiedErrorId : The server has returned the following error: inv
     alid enumeration context.,Microsoft.ActiveDirectory.Management.Commands.Ge
    tADUser
  </code></pre>
  
  <p>I am lost to why I am getting this error on one domain but not another.</p>