Import-Module ActiveDirectory
$date = (Get-Date).AddDays(-90)
$Departments = Get-ADUser -Filter {lastlogontimestamp -gt $date} -property * | Select SamAccountName,Name,CanonicalName,EmailAddress,PasswordLastSet,WhenCreated,PasswordExpired,PasswordNeverExpires,ProfilePath,Department,Title,Manager,@{Name="Disabled"; Exp={$_.useraccountcontrol -band 2}} |?{$_.Disabled -eq 0} | select Department | sort-object Department -Unique