title: Powershell script to check status of user in AD
body: <p>Powershell script to check status of user accounts are enabled or disabled using a text file which has names ( first name and last name)</p>
  
  <p>I am trying to find out if a user account is enabled or disabled in AD from a list of users which is a text file using powershell.</p>
  
  <p>I have tried to get the code to fetch names from a list of users in a text file and check if their accounts are enabled or disabled in AD. But the code below is giving an error message.</p>
  
  <pre><code>Get-Content -Path users.txt |
  ForEach-Object {
  Get-ADUser -LDAPFilter "(samaccountname=$_)" |
  Select-Object -Property samaccountname,enabled
  }
  </code></pre>
  
  <p>I think its something to do with the samaccountname as I just have the names in simple text format ( firstname lastname).</p>