title: Extract AD User information via ADSI
body: <p>How can I get these properties for a user via ADSI LDAP, these are the properties from <code>Get-ADUser</code>, I need the equivalent for ADSI.</p>
  
  <ul>
  <li>Enabled</li>
  <li>PasswordNeverExpires</li>
  <li>PasswordExpired</li>
  <li>Name</li>
  <li>SamAccountName</li>
  <li>Mail</li>
  <li>PasswordLastSet</li>
  </ul>
  
  <p>My objective is to query the entire domain for all users and get these attributes.</p>
  
  <p>I tried with the <code>Get-ADUser</code> cmdlet and it timed out when querying for the users.</p>
  
  <pre class="lang-psh prettyprint-override"><code>Get-ADUser -Filter * -Properties enabled,PasswordNeverExpires,passwordexpired,Name,SamAccountName,mail,passwordla‌​stset -server sc |
     where {$_.Enabled -eq "True"} |
     where { $_.PasswordNeverExpires -eq $false } |
     where { $_.passwordexpired -eq $false } |
     Select Name,SamAccountName,mail,
            @{l='PasswordExpires';e={$_.passwordlastset+(Get-ADDefa‌​ultDomainPasswordPolicy).MaxPasswordAge}},
            @{l='DaystoExpire';e={(New-TimeSpan -Start (get-date) -end ($_.passwordlastset+(Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge)).days}}
  </code></pre>
  
  <p>The above command works on a couple of users but if I query a large set of users it gives invalid enumeration context.</p>