title: Get-ADUser password expiration for users in specific OUs
body: <p>I can get a valid "msDS-UserPasswordExpiryTimeComputed" property for a single user:</p>
  
  <pre><code>(([DateTime]::FromFileTime((Get-ADUser $UserName -Properties "msDS-UserPasswordExpiryTimeComputed")."msDS-UserPasswordExpiryTimeComputed")))
  </code></pre>
  
  <p>But I'm having trouble targeting a group of specific users.  My larger script is intended to pull various AD user attributes from accounts in particular OUs and export to csv.  All of the properties are populated as expected, except for the "PasswordExpiry" object.</p>
  
  <p>The below sample returns a bogus "PasswordExpiry" date of "12/31/1600" for every user. 
   "C:\UserList.txt" contains sAMAccountNames one per line.</p>
  
  <pre><code>$UserList=Get-Content "C:\UserList.txt"
  ForEach ($UserName in $UserList) {Get-ADUser "$UserName" -Properties * | 
  Select-Object sAMAccountName,whenCreated, `
  @{Name="lastLogon";Expression={[DateTime]::FromFileTime($_.lastLogon)}}, `
  @{Name="pwdLastSet";Expression={[DateTime]::FromFileTime($_.pwdLastSet)}}, `
  @{Name="PasswordExpiry";Expression={[DateTime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}}, `
  cannotChangePassword,passwordNeverExpires, `
  @{Name="GroupMember";Expression={($_ | Select -ExpandProperty MemberOf) | Where {$_ -Like "*Desired.Group*"}}} |  
  Export-Csv -Path "C:\UserInfo.csv" -Append -NoTypeInformation}
  </code></pre>
  
  <hr>
  
  <p>This works if I wanted to query all AD users:</p>
  
  <pre><code>Get-ADUser -Filter * –Properties sAMAccountName,"msDS-UserPasswordExpiryTimeComputed" |
  Select-Object -Property sAMAccountName,@{Name="PasswordExpiry";Expression={[DateTime]::FromFileTime($_.“msDS-UserPasswordExpiryTimeComputed”)}}
  </code></pre>
  
  <p>But if I add the [-SearchBase "OU=Users,DC=Domain,DC=local"] parameter to Get-ADUser, I get null output for "PasswordExpiry".  I guess I could try parsing the entire output with some post processing.  Seems like touching more than I should have to though.</p>
  
  <p>I know that I can calculate the expiration based off the "pwdLastSet" attribute.  But I want to pull the actual value because age policy might be unknown.  Any help is appreciated.</p>