I wanted to write a powershell script to retrieve the last logon property of an Active Directory User. Here is how I came to the final script.
First of all: to get the domain users, use the command:
- Get-QADUser
This will return a list of all the domain users. As it will not return the property LastLogon, you have to include it. And for a better performance you can exclude the default properties
- Get-QADUser -IncludedProperties name,lastlogon
You will now have all your domain users and the property Lastlogon. To list them:
- Get-QADUser -DontUseDefaultIncludedProperties -IncludedProperties lastlogon | Select-Object Name,LastLogon
Next, to export it to a csv file (use the NoTypeInformation parameter to remove the .NET object header):
- Get-QADUser -DontUseDefaultIncludedProperties -IncludedProperties lastlogon | Select-Object Name,LastLogon | Export-Csv c:\ADusers.csv -NoTypeInformation
BTW: I used PowerGUI Script Editor








