title: Using PowerShell how can I search and filter an array of exported Active Directory users like I can with Get-ADUser?
body: <p>I have a PowerShell script that compares the contents of a CSV file with Active Directory. The CSV file contains a list of demographic information of people already in AD. One of the columns is "emplid". The values in this field correspond to the values of the "employeeID" attribute of user objects in AD. So, I currently use this "emplid" property to cross reference AD and find the corresponding user accounts. To do this I use a line similar to this:</p>
  
  <pre><code>$UserAccounts = $ListOfEmloyeeIDs | ForEach-Object {Get-ADUser -Properties * -Filter {employeeID -Eq $_}}
  </code></pre>
  
  <p>I then use this to add those user accounts to a security group:</p>
  
  <pre><code>$UserAccounts.SamAccountName | ForEach-Object {Add-ADGroupMember -Identity SpecialSecurityGroup -Members $_}
  </code></pre>
  
  <p>The problem is with the first line. There are thousands of user accounts and the script can take hours to run. This has also led to complaints from the AD admins. What I would like to do is load all active AD users into a variable (which takes less than 2 minutes to run) using:</p>
  
  <pre><code>$ADPeopleActive = Get-ADUser -SearchBase "OU=People,DC=MyAD,DC=com" -Properties EmployeeID -Filter {Enabled -Eq $True}
  </code></pre>
  
  <p>Then I would like to do my cross reference against this array and build a list of SamAccountNames to feed to something like my second line to populate my security group.</p>
  
  <p>My problem is I can't figure out a way to do this cross reference against an array that I've built the same way I can cross reference with AD using Get-ADuser. Can anyone help?</p>