title: Working with a list of AD 'displayNames' in Powershell. How to indicate which users were not found?
body: <p>I have written enough PS code to go through a list of <strong>displayNames</strong> (e.g &quot;John Smith&quot;, &quot;Taylor Hanson&quot; - all stored on seperate lines of a txt file) to spit back enough data into another text file that can be used for mailmerge etc. Convincing thousands of employees to simply update Windows is like breaking stones! It has to be automatted to some degree...</p>
  <p>Here is the code... the functions that let the user open a specific text file and later save are out of view...</p>
  <pre><code>$displayname = @()
  $names = get-content $FileIN
  foreach ($name in $names) {
  
  
      $displaynamedetails = Get-ADUser -filter { DisplayName -eq $name } | Select Name, GivenName,  Surname, UserPrincipalName
      $displayname += $displaynamedetails
  
  }
  
  $displayname | Export-Csv -NoTypeInformation -path $fileOUT -Encoding UTF8
  </code></pre>
  <p>From time to time, a name might be spelled incorrectly in the list, or the employee may have left the organisation.</p>
  <p>Is there any way that a statement such as '<strong>Not Found</strong>' can be written to the specific line of the text file if an error is ever made (so that an easy side-by-side comparison of the two files can be made?</p>
  <p>For most of the other solutions I've tried to find, the answers are based around the samAccoutName or merging the first and last names together. Here, i am specifically interested in displaynames.</p>
  <p>Thanks</p>