Scheduled Task: LastLogon PowerShell Script with Email
Posted on 2016-10-25
Good Morning, Experts!
Firstly, I will be the first to admit: I am a PowerShell amateur.
What we are wanting to do is setup a script that will:
- Audit all Active Directory Users, to see when their last logon was (lastlogon)
- Export this information to a .csv file labeled lastlogon-audit-<yyyymmdd>
- Include the following LDAP fields, each in its own column: Login Name, Display Name, Email Address, Description, Account Disabled, Last Logon
- If possible, highlight users who have not logged in for more than 7 days
- Email that report to a specific email address
We have a similar setup for Password Expiration, though that script is more sophisticated, in that it emails the users whose passwords will expire in 14 days, and outlines password rules. That script predates my time here.