Inactive Users Report with PowerShell



  • This script shows you everybody that has not logged into a computer on the domain for the last 20 (can be changed) days in the Users OU. It then creates a csv spreadsheet, saves it to a network drive, creates an email, then attaches the spreadsheet to the email before sending it. It can be modified to work with both an on-premise exchange and O365, as long as you plugin the address to your Exchange box.

    Search-ADAccount -AccountInactive -TimeSpan 20.00:00:00 -UsersOnly -SearchBase "CN=Users,DC=<domain>,DC=com" | Select-Object Name,Enabled,LastLogonDate | sort enabled | export-csv \\server\folder\inactive_users.csv
    Send-MailMessage -From <arbitrary>@<domain>.com -To [email protected]<domain>.com,person(n+1)@<domain>.com -Subject "Inactive Users" -SmtpServer <YourExchangeURI> -Attachments \\server\folder\inactive_users.csv
    

    A part of the NerdyDad's PowerShell Scripts Series



Looks like your connection to MangoLassi was lost, please wait while we try to reconnect.