none
Script to find users that have not logged in last 180 days RRS feed

  • Question

  • I have a script I have put together that I will post below. I am having two issues, one I need to have the users managers listed, and two I have a lot of results that show no date for last logged in. I am not sure why that is. I only want to see users that have not logged in in the last 180 days.

    Any help is appreciated.

    $To = "xxxx@xxxx.com"
    $From = "xxxx@xx.com"
    $Company = "company name"
    $Subject = "AD Report" 
    $Body = "$Company Report Attached" 
    $SMTPServer = "mailrealay.com" 
    $SMTPPort = "25"
    $file = "c:\temp\ADUsers.csv"
    $HTMLCSS = @"
    <style>
    TABLE {border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
    TH {border-width: 1px;padding: 3px;border-style: solid;border-color: black;background-color: #00ff00;}
    TD {border-width: 1px;padding: 3px;border-style: solid;border-color: black;}
    </style>
    <title>
    AD Report
    </title>
    "@


    Search-ADAccount -usersonly -AccountInactive -TimeSpan 180.00:00:00 | ?{$_.enabled -eq $true} |
     select name, givenname, UserPrincipalName, lastlogondate, DistinguishedName, manager | export-csv $file -NoTypeInformation

    Send-MailMessage -From $From -to $To -Subject $Subject `
    -Body $Body -Attachments $file -SmtpServer $SMTPServer -port $SMTPPort

    • Moved by Bill_Stewart Wednesday, May 9, 2018 2:40 PM This is not "scripts on demand"
    Tuesday, March 20, 2018 6:55 PM

All replies