title: Get Active Directory Information from PC's in a text file - Powershell
body: <p>I am running to an issue with a Powershell command line I'm attempting to run.  What we are needing is to get the PC Name and LastLogonDate from PC's in a list of text files with Powershell.</p>
  
  <p>Here is the code I'm attempting to run:</p>
  
  <pre><code>Get-Content C:\Hosts.txt | ForEach-Object{Get-ADComputer $_ -Properties Name,LastLogonDate | Select-Object Name,LastLogonDate | Export-Csv C:\Output.csv}
  </code></pre>
  
  <p>When I run that code I get an error stating: "Cannot find a object with identity: 'ComputerName'" despite the fact that the PC is truly in AD. What is confusing me is that everything after the ForEach-Object runs great if you run it by itself. When you add the Get-Content and ForEach-Object the errors begin. I can see from the error messages that each individual computer name is being read from the text file, but I wonder if it is passing it in a way the Get-ADComputer doesn't like.</p>