How to Alert Admin When a New Users Added to the AD Group

Let’s have a look at how to create a easy administrator notification system when somebody provides a new consumer to the vital Active Directory safety group. For instance you need to monitor the adjustments of area administrator group, and if a new consumer is added to it, you need to get the corresponding notification (by e-mail or in a pop-up alert message).

There are to methods to implement it:

  1. You can allow the occasion audit on the area controllers and monitor the occasion of including a new consumer to the safety group (EventID 4728);
  2. You can retailer a native textual content file with the record of customers of a sure group and often evaluate it to the present members record of the area group.


  • Audit of Adding a User to a Group on the Domain Controller
  • Comparing the Current Members of the Domain Group with the Saved Template

Audit of Adding a User to a Group on the Domain Controller

If the audit coverage is enabled in the GPO part Computer Configuration -> Windows Settings -> Security Settings -> Advanced Audit Configuration -> Account Management -> Audit Security Group Management, the occasion with the EventID 4732 (A member was added to a security-enabled world group) seems in the Security log after including a new consumer to any Active Directory group.

Audit Security Group Management - domain controller policy

Using PowerShell, you may monitor this occasion in the Security log. For instance, let’s show all occasions with this ID on the area controller for the final 24 hours. To make it extra handy, we’ll show the title of the AD group that has modified, the title of the added account and the administrator who has added this consumer to the group. The script is comparable to the one given in the article .

$CurrTime = (get-date) - (new-timespan -hour 24)
Get-WinEvent -FilterHashtable @| Foreach

check ad group changes by event on a DC

Then create a new scheduler process on the area controller to be triggered by the occasion with the ID 4732. When this occasion happens, a message will probably be despatched to the consumer. (The articles describes how to hyperlink a script to an occasion, I gained’t do it right here once more.)

However, the drawback is that the safety log of just one DC is checked. If a consumer has been added to a group on one other area controller, you gained’t see this occasion. Of course, you may subscribe to the occasions of a number of DCs or run the script on every controller, but when there are a lot of DCs in the area, it isn’t very handy.

Tip. The instance of checking all DCs in the area in a loop and gathering occasions from them can appears like this (the code instance is taken from the article ):

$time = (get-date) - (new-timespan -hour 124)
$DCs = Get-ADDomainController -Filter *
foreach ($DC in $DCs) Foreach

Let’s think about one other strategy.

Comparing the Current Members of the Domain Group with the Saved Template

Let’s show the record of customers in the “Domain Admin” group utilizing the cmdlet and save the ensuing record to a textual content file (we’re constructing a recursive record of customers together with nested teams):

(Get-ADGroupMember -Identity "Domain Admins" -recursive).Name | Out-File C:PSDomainAdmins.txt

Then add a new consumer to the “Domain Admins” group and save the record of customers once more to one other file:

(Get-ADGroupMember -Identity "Domain Admins" -recursive).Name | Out-File C:PSDomainAdminsPrecise.txt

Now evaluate two recordsdata and show the distinction in the lists:

$old_adgroup_members=GC C:PSDomainAdmins.txt
$new_adgroup_members=GC C:PSDomainAdminsPrecise.txt
$diff=Compare-Object -ReferenceObject $old_adgroup_members -DistinctionObject $new_adgroup_members | Select-Object -ExpandProperty EnterObject
write-host $diff

The new account added to the AD group is displayed.

You may also show the message in the console:

$outcome=(Compare-Object -ReferenceObject $old_adgroup_members -DistinctionObject $diff | Where-Object | Select-Object -ExpandProperty EnterObject) -join ", "
If ($outcome)

alert then user is add to the ad admins group

Or ship an electronic mail utilizing Send-MailMessage cmdlet:

If ($outcome)

You can save this script to a file admins_group_changes.ps1 and run it often utilizing Task Scheduler (you may ). Create a new Scheduler job that can run your PowerShell script each 24 hours. It will evaluate the members of the Domain Admins group with the record saved domestically.

$Trigger= New-ScheduledTaskTrigger -At 17:00am -Daily
$Action= New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "C:PSadmins_group_changes.ps1 "
Register-ScheduledTask -TaskName "Check Domain Group Changes" -Trigger $Trigger -User $User -Action $Action -RunLevel Highest –Force

Thus, the members of the Domain administrator group will probably be checked as soon as a day, and if there are any adjustments, an administrator will get an alert (in a pop-up window or by electronic mail).

Check Also

How to Remove Built-in Apps, Features & Editions from a Windows 10 Install Image…

In this information we’ll present how to take away Microsoft Store provisioned apps, options (capabilities), …

Leave a Reply

Your email address will not be published. Required fields are marked *