title: Export AD Info CSV based on User Name input CSV powershell script
body: <p>I need to pass in a list of Users and get back a CSV with Name, SamAccountName, email</p>
  
  <p>My Input CSV is as follows:</p>
  
  <pre><code>"John Doe"
  "Jane Doe"
  </code></pre>
  
  <p>Here's the current code I'm using. I'm not sure what the problem is. The users actually do exist under the "DC" specified...</p>
  
  <pre><code>Import-Module ActiveDirectory
  Function Get-ADUsersDetailsCSV
  {
      [CmdletBinding()]
      Param
      (
      [Parameter(Mandatory=$True,Position=1)]
      [String]$InCSV,
  
      [Parameter(Mandatory=$True)]
      [String]$OutCSV
      )
  
  If($InCSV)
  {
      If(Test-Path -Path $InCSV)
      {
          $USERS = Import-CSV $InCSV -Header Name
          $USERS|Foreach{Get-ADUser $_.Name -Properties * |Select Name, SAMAccountName, mail}|Export-CSV -Path $OutCSV
  
      } #End Test that the files exist
  
      Else
      {
          Write-Warning "Cannot find path '$InCSV' because it does not exist."
      }
  
  
  } #End Ensure Input and Output files were provided
  
  } #End Function Get-UsersDetailsCSV
  </code></pre>
  
  <p>Here's the error:</p>
  
  <pre><code>Get-ADUser : Cannot find an object with identity: 'John Doe' under: 'DC=blah,DC=com'.
  At U:\data\GetADUserInfo PS Script\GetADUsersDetailsCSV.psm1:19 char:28
  +             $USERS|Foreach{Get-ADUser $_.Name -Properties * |Select Name, SAMAcc ...
  +                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  + CategoryInfo          : ObjectNotFound: (Name:ADUser) [Get-ADUser], ADIdentityNotFoundException
  + FullyQualifiedErrorId : Cannot find an object with identity: 'John Doe' under: 'DC=blah,DC=com'.,Microsoft.ActiveDirectory.Management.Commands.GetADUser
  </code></pre>