0 votes

We have been checking to see who users were most recently disabled so we can manually check a few things. Here is the code I used to get that information using the Scheduled Tasks.

I realize that the web interface offers this same functionality, which is actually much easier. But this worked well for us.

Note, this is modified from a template I received from a previous post (Email when there is a problem). The instructions for creating the script can be followed in that post.

import-module Adaxes

$numDays = -10
$to = "itnotify@domain.com" ## TODO: Change this
$subject = "Adaxes users disabled within the last $numDays days"
$htmlReportHeader = @"
<b>Adaxes users disabled in the last $numDays days</b><br/><br/>
<table border="1">
    <tr>
        <th>User</th>
        <th>Modified date</th>
    </tr>
"@

$Report_body = Get-AdmUser -LDAPFilter {(useraccountcontrol:1.2.840.113556.1.4.803:=2)} -Properties whenChanged | Where-Object {$_.whenChanged -gt (Get-Date).AddDays($numDays)} | Select-Object Name, whenChanged
$htmlReportFooter = "<hr /><p><i>Please do not reply to this e-mail, it has been sent to you for notification purposes only.</i></p>" # TODO: modify me

$count=0
foreach ($record in $Report_body)
{
    $recordName = $record.Name 
    $recordModified = $record.whenchanged
    $htmlReportHeader += "<tr valign='top'><td>$recordName</td><td>$recordModified</td></tr>"
    $count++
}
$htmlBody = $htmlReportHeader + "</table><p>Total Users: $count </p>" + $htmlReportFooter

# Bind to the Service Log
$path = $Context.GetWellKnownContainerPath("ServiceLog")
$serviceLog = $Context.BindToObject($path)

 #Write-Output $htmlBody

if ($Report_body)
{
    # Send report
    $Context.SendMail($to, $subject, $NULL, $htmlBody)
}

I hope someone finds it useful!

by (290 points)
0

Hello,

Thanks for your input, we appreciate it very much!

0

Thank you for cooking this up many years ago. Much appreciated.

Please log in or register to answer this question.

Related questions

0 votes
1 answer

We have four OUs in Active Directory (Pending Deletion, Disabled with Mail Delegates, Disabled with HR Extensions and Disabled_Temp_Leave) that users are moved to prior to their eventual ... past 7 days have been moved to one of 4 of these OUs. Thanks!

asked Jun 3, 2021 by RayBilyk (240 points)
0 votes
1 answer

Is it possible to run a report to get users disabled in the last 24 hours?

asked Jun 10, 2020 by peggleg (110 points)
0 votes
1 answer

Hi, Does someone already have a script that I can run as a scheduled task that will email a list of enabled active directory accounts that have exchange mailboxes? I ... First, Middle, Last, Title, Location and Email address. Any assistance is appreciated.

asked Feb 2, 2017 by mdedmon (150 points)
0 votes
1 answer

I would like to generate a report that will show me the recently modified "ipPhone" property field, which contains our Extensions, so that our Help Desk can use that to update ... /script-repositor ... d-s455.htm How would I use that to make this possible?

asked Mar 21, 2019 by rurbaniak (1.4k points)
0 votes
1 answer

Hello, My "Never logged on users" report also shows users that recently logged on. My "Recently logged on users" report shows nobody. How can we change this? Best regards, Roel

asked Jan 30, 2013 by roel (40 points)
3,541 questions
3,232 answers
8,225 comments
547,802 users