# PS1 script to get LastLogon and PwdLastSet attributes
cls
Import-Module ActiveDirectory

function myfunc ($ou, $path) {
   $myObj = Get-QADUser -searchroot $path -SearchScope OneLevel -SizeLimit 0 -IncludedProperties lastLogon,lastLogonTimestamp, pwdLastSet -Enabled | Select Name, lastLogon, lastLogonTimestamp, pwdLastSet | Sort-Object Name
   $myObj | Add-Member NoteProperty OU $ou
   $myObj
}

$search = "OU=yourOU, DC=yourdomain, Dc=com"
$arr_ou = Get-ADOrganizationalUnit -Filter 'Name -like "*"' -SearchBase $search | Sort-Object
foreach ($ou in $arr_ou)
{     
   myfunc $ou.Name $ou.DistinguishedName    
}