When it is written
A domain controller writes 5138 when a deleted object is brought back (undeleted), for example when an administrator restores it from the Active Directory Recycle Bin. Microsoft: the event is written only if the container the object is restored to has an auditing entry for the Create action for that class, such as Create User objects. Only successful restores are logged, by the domain controller that performed them.
Old DN (OldObjectDN) is where the deleted object was kept, in the Deleted Objects container under a changed name that ends with DEL: and its GUID. New DN (NewObjectDN) is where it lives again. The object keeps its GUID, so earlier events about it can be found by ObjectGUID.
How to turn it on
Advanced audit policy subcategory Audit Directory Service Changes, Success. Set it in a Group Policy object linked to the computers that write the event:
Computer Configuration > Policies > Windows Settings > Security Settings > Advanced Audit Policy Configuration > Audit Policies > DS Access > Audit Directory Service Changes| Computer | Audit | Note |
|---|---|---|
| Domain controllers | Success | Microsoft recommends Success auditing in both its general and stronger baselines, with SACLs designed for the important objects, classes and operations (it names changes to AdminSDHolder and the Domain Admins group). The subcategory has no failure events; failed access attempts are logged by Audit Directory Service Access. |
| Member servers | Not logged | Microsoft says the subcategory makes sense only on domain controllers. |
| Workstations | Not logged | Microsoft says the subcategory makes sense only on domain controllers. |
auditpol /get /subcategory:"Directory Service Changes"auditpol /set /subcategory:"Directory Service Changes" /success:enableauditpol /get /subcategory:"{0CCE923C-69AE-11D9-BED3-505054503030}"Run the commands in an elevated prompt on a computer that writes the event. Subcategory settings take effect only when the security option Audit: Force audit policy subcategory settings (Windows Vista or later) to override audit policy category settings is enabled (the default), and a Group Policy object that sets advanced audit policy replaces local changes at its next refresh. Microsoft's advanced audit policy reference
Microsoft states that 5138 is generated only if the container the object is restored to has an auditing entry for the Create action for the restored class. For the rule on this page, add on the domain root a Success entry for Everyone with Create User objects, Create Computer objects and Create Group objects, applied to this object and all descendant objects, and turn on Audit Directory Service Changes (Success) on every domain controller.
The default SACL of the domain object does not audit creation, so it produces no 5138. Microsoft's Defender for Identity setup puts its entries (Full control minus the read permissions) on descendant user, group, computer and managed service account objects, not on the containers objects are restored to: Microsoft does not say whether those entries make a restore write 5138, so do not rely on them for it.
Fields
In Event Viewer order. The field names are those of the event XML, from the event template that ships with Windows.
| Field | What it holds | Since |
|---|---|---|
Security IDSubjectUserSidSubject | SID of the account that restored the object. Event Viewer resolves it to a name. | v0 |
Account NameSubjectUserNameSubject | Name of the account that restored the object. | v0 |
Account DomainSubjectDomainNameSubject | Domain of the account that restored the object, usually as a NetBIOS name. | v0 |
Logon IDSubjectLogonIdSubject | Logon ID of the session that restored the object, in hexadecimal. Matches the 4624 event of that session on this domain controller. | v0 |
NameDSNameDirectory Service | Name of the Active Directory domain in which the object was undeleted, as a DNS name. | v0 |
TypeDSTypeDirectory Service | Directory service type. %%14676 (Active Directory Domain Services) on domain controllers. | v0 |
Old DNOldObjectDNObject | Distinguished name the object had while deleted. For a restore from the Recycle Bin it points into the Deleted Objects container, with the old name followed by an escaped line break (\0A), the text DEL: and the object GUID. | v0 |
New DNNewObjectDNObject | Distinguished name of the restored object, in the container it was restored to. | v0 |
GUIDObjectGUIDObject | objectGUID of the object, in braces. It is the same before deletion, while deleted and after the restore. | v0 |
ClassObjectClassObjectRead by 1 rule | Class of the restored object, for example user, computer, group or organizationalUnit. | v0 |
Correlation IDOpCorrelationIDOperation | Correlation ID shared by every event of the same LDAP operation, in braces. | v0 |
Application Correlation IDAppCorrelationIDOperation | Application Correlation ID. Microsoft says it is not in use and always holds a dash. | v0 |
Values to know
Class ObjectClass
| Value | Meaning | Signal |
|---|---|---|
user | A restored user accountThe rule reads it. A restored account is usable again once it has a password and is enabled; confirm the request behind it. | Attack signal |
computer | A restored computer accountThe rule reads it. Also check whether the computer was given a new password afterwards. | Attack signal |
group | A restored groupThe rule reads it. Check what the group grants and who is in it now. | Attack signal |
organizationalUnit, groupPolicyContainer and other classes | Other restored objectsUsually the repair of an accidental deletion. | Worth knowing |
Old DN OldObjectDN
| Value | Meaning | Signal |
|---|---|---|
Contains \0ADEL:<GUID>,CN=Deleted Objects, | The name a deleted object carries in the Deleted Objects containerMicrosoft's sample event shows this form. The GUID in it is the object's own objectGUID. | Expected |
Volume and noise
Rare. Restores are manual administrative actions, and Microsoft suggests monitoring every undelete event because the operation is not performed often, confirming that each one had a reason.
Keeping it manageable
- Keep every 5138: the volume is negligible and the rule reads user, computer and group restores.
- Put the Create entry where it reaches every container a restore can target: an inheritable entry on the domain root covers the OUs below it, so a restore into an unexpected OU is not missed.
- Collect 4724 (password reset) and 4722 (account enabled) next to it: the hypothesis for this attack looks for a restored account that the same actor then resets and enables.
Sample event
Version 0, with made-up values.
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name="Microsoft-Windows-Security-Auditing" Guid="{54849625-5478-4994-a5ba-3e3b0328c30d}" />
<EventID>5138</EventID>
<Version>0</Version>
<Level>0</Level>
<Task>14081</Task>
<Opcode>0</Opcode>
<Keywords>0x8020000000000000</Keywords>
<TimeCreated SystemTime="2026-11-18T09:30:12.4567890Z" />
<EventRecordID>1048576</EventRecordID>
<Correlation />
<Execution ProcessID="712" ThreadID="2408" />
<Channel>Security</Channel>
<Computer>DC01.corp.example.com</Computer>
<Security />
</System>
<EventData>
<Data Name="OpCorrelationID">{2d7f9a14-6c3e-4b81-a5d2-0e9c4b7f1a63}</Data>
<Data Name="AppCorrelationID">-</Data>
<Data Name="SubjectUserSid">S-1-5-21-1004336348-1177238915-682003330-1105</Data>
<Data Name="SubjectUserName">alice</Data>
<Data Name="SubjectDomainName">CORP</Data>
<Data Name="SubjectLogonId">0x3e5a21</Data>
<Data Name="DSName">corp.example.com</Data>
<Data Name="DSType">%%14676</Data>
<Data Name="OldObjectDN">CN=bob\0ADEL:6a1e3c9d-4f27-4b05-8e3a-d2c71f094b8e,CN=Deleted Objects,DC=corp,DC=example,DC=com</Data>
<Data Name="NewObjectDN">CN=bob,OU=Staff,DC=corp,DC=example,DC=com</Data>
<Data Name="ObjectGUID">{6a1e3c9d-4f27-4b05-8e3a-d2c71f094b8e}</Data>
<Data Name="ObjectClass">user</Data>
</EventData>
</Event>Attacks this event reveals
Detection rules that read this event:
Frequently asked questions
Does 5138 need the Active Directory Recycle Bin?
No. The event is written whenever a deleted object is undeleted; Microsoft gives a restore from the Recycle Bin as an example, not as a requirement.
Why was no 5138 logged for a restore?
The container the object was restored to needs an auditing entry for Create on that class, and Audit Directory Service Changes must be on for the domain controller that did the restore. An entry on the domain root that applies to all descendant objects covers every OU.
What should I check after an account was restored?
Who restored it and whether there was a request for it; whether the same account then reset its password (4724) or enabled it (4722); which groups it is a member of again; and where it signs in from next (4624).