ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Inactive Users Report with PowerShell

    Self Promotion
    scripts powershell users office 365 office365 o365 exchange nerdydad ps scripts
    1
    1
    1.3k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • NerdyDadN
      NerdyDad
      last edited by scottalanmiller

      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 person1@<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

      1 Reply Last reply Reply Quote 1
      • 1 / 1
      • First post
        Last post