I had to decommission a domain that was being used by a small number of users. I needed a list of all users that were still active on it. The below script will list all users that recently logged into the domain and will sort the list by LastlogonDate.
Import-Module ActiveDirectory Get-ADUser -Filter * -Properties * | select DisplayName,LastlogonDate |Sort-Object -Property LastlogonDate -Descending | Export-Csv C:\support\LogonReport.csv
All available properties you can use:
Property AccountExpirationDate AccountLockoutTime AccountNotDelegated AllowReversiblePasswordEncryption BadLogonCount CannotChangePassword CanonicalName Certificates ChangePasswordAtLogon City CN Company Country Created Deleted Department Description DisplayName DistinguishedName Division DoesNotRequirePreAuth EmailAddress EmployeeID EmployeeNumber Enabled Fax GivenName HomeDirectory HomedirRequired HomeDrive HomePage HomePhone Initials LastBadPasswordAttempt LastKnownParent LastLogonDate LockedOut LogonWorkstations Manager MemberOf MNSLogonAccount MobilePhone Modified Name ObjectCategory ObjectClass ObjectGUID Office OfficePhone Organization OtherName PasswordExpired PasswordLastSet PasswordNeverExpires PasswordNotRequired POBox PostalCode PrimaryGroup ProfilePath ProtectedFromAccidentalDeletion SamAccountName ScriptPath ServicePrincipalNames SID SIDHistory SmartcardLogonRequired State StreetAddress Surname Title TrustedForDelegation TrustedToAuthForDelegation UseDESKeyOnly UserPrincipalName