title: Powershell to filter user latest last login and last login greater than X number of days
body: <p>I am trying to get AD Users with a last login greater than X number of days, and also retrieve their managers email.</p>
  
  <p>I have searched a lot but not getting what I need, right now below is what I have. It does not filter users with latest login timestamp or not logged on in more than X days.</p>
  
  <p>Once I am able to filter both these attributes I can add the email syntax for each user to send email to their manager.</p>
  
  <pre><code>$dcs = Get-ADDomainController -Filter * | Select-Object -Property Name
  foreach ($dc in $dcs)
  {
  $lastlogon = Get-ADUser -Filter * -SearchBase  "OU=Sandbox_Users,DC=twi-test,DC=com" -Properties * | Select-Object -Property displayname,lastlogon,samaccountname,EmailAddress,@{Name = "Manager" ; Expression = {(Get-ADUser $_.Manager).Name}},@{Name = "ManagerEmail" ;`
   Expression = {(Get-ADUser $_.manager -Properties emailaddress).EmailAddress}
   }}
  </code></pre>