title: Using PowerShell to query Active Directory and add data to new column of existing csv
body: <p>I have a CSV with hundreds of usernames listed on it. In PowerShell I would like to run <code>Get-ADUser</code> and output their <code>DisplayName</code> in the adjacent cell. I also want to keep all the other information within the correct rows, and make sure if any usernames are not found in AD, that the output doesn't write the following <code>DisplayName</code> out of order. Can someone help me figure this out? I'm relatively new to PowerShell, and very new to using it to modify Excel. </p>
  
  <p>For confidentiality, lets say my spreadsheet looks like this:</p>
  
  <p><img src="https://i.stack.imgur.com/nYPbX.png" alt="Users"></p>
  
  <p>This is what I have so far...</p>
  
  <pre><code>$userlist = Get-Content $home\Desktop\names.csv
  
  ForEach ($user in $userlist) {
      Get-ADUser $user -Properties DisplayName | 
            Select-Object Name,DisplayName |
            Export-CSV $home\Desktop\new_names.csv -NoTypeInformation
  }
  </code></pre>