"A whole folder just vanished from the shared drive. Can you find out who deleted it?"
If you look after a Windows file server, you will get this request sooner or later. The bad news: unless file system auditing was set up beforehand, the Security log will not tell you who deleted the file. Auditing only records from the moment you turn it on; it cannot go back in time. And files deleted over an SMB share usually don't go to anyone's Recycle Bin either.
This post walks through how to answer "who deleted what, and when" using only what ships with Windows, from setup to reading the logs:
- Setting up the audit policy and SACLs
- Pairing Event IDs 4663 and 4660 to identify a delete
- Telling a delete apart from a rename or move
- Using the USN journal to find where a moved file went (the Security log doesn't record this)
It applies to Windows Server 2016 and later (Windows 10/11 work the same way), with shares on NTFS or ReFS.
Before you start
Recording file access means recording what people do. If you do this in an organization, follow your policies and let the people being monitored know in advance. These steps also change audit settings, so try them in a test environment first, and save your current audit policy withauditpol /backup /file:<file>.
1. Turn on auditing (do this before you need it)
To get file operations into the Security log you need both an audit policy and a SACL (audit entries) on the folder. Either one alone records nothing.
Audit policy
In an elevated PowerShell, enable these Object Access subcategories. Subcategory names are localized, so using the GUIDs works on any display language.
# File System (success and failure): 4663 / 4660 and friends auditpol /set /subcategory:"{0CCE921D-69AE-11D9-BED3-505054503030}" /success:enable /failure:enable # Handle Manipulation (failure only): records denied attempts (4656) auditpol /set /subcategory:"{0CCE9223-69AE-11D9-BED3-505054503030}" /failure:enable # File Share (success): lets you find the client IP address (5140) auditpol /set /subcategory:"{0CCE9224-69AE-11D9-BED3-505054503030}" /success:enable Check the result with auditpol /get /category:*. In a domain where a GPO uses Advanced Audit Policy Configuration, set it in the GPO instead, or it will be overwritten.
SACL
Next, put a SACL on the folder you want to watch. You can do this in Explorer (Properties → Security → Advanced → Auditing), but here is the PowerShell version. As with the audit policy, Everyone is given by its SID (S-1-1-0) so it works on any language.
$path = 'D:\Share' # Everyone, by SID (language-independent) $identity = [System.Security.Principal.SecurityIdentifier]::new('S-1-1-0') # Audit only reading/writing contents, deleting and permission changes. # Plain Read / Write also include attribute reads etc. and flood the log. $rights = [System.Security.AccessControl.FileSystemRights]'ReadData, WriteData, AppendData, Delete, ChangePermissions, TakeOwnership' $rule = [System.Security.AccessControl.FileSystemAuditRule]::new( $identity, $rights, 'ContainerInherit, ObjectInherit', # inherit to subfolders and files 'None', 'Success, Failure') $acl = Get-Acl -LiteralPath $path -Audit $acl.AddAuditRule($rule) Set-Acl -LiteralPath $path -AclObject $acl With inheritance on, files below the folder are covered too. Subfolders that have inheritance disabled need their own entry.
If all you care about is deletes, set $rights to just 'Delete'; that cuts log volume a lot. Auditing reads makes the event count grow by orders of magnitude.
Security log size
Once file auditing is on, the Security log fills up fast. Check the current maximum size and raise it if needed.
# Show the current settings (maxSize is in bytes) wevtutil gl Security # Set the maximum size to 1 GB wevtutil sl Security /ms:1073741824 1 GB is only a starting point. On a busy server even that can roll over within a few days, so check how far back your log actually reaches.
2. A delete is "4663 + 4660"
This is where most people get stuck. These are the main events involved in file operations:
| Event ID | Meaning |
|---|---|
| 4656 | A handle to an object was requested (an attempt to open; denied attempts show up here) |
| 4663 | An attempt was made to access an object (an access right was actually used) |
| 4660 | An object was deleted |
| 4659 | A handle to an object was requested with intent to delete |
| 4658 | The handle to an object was closed |
| 4670 | Permissions on an object were changed |
When a file is deleted, you get a 4663 and a 4660:
| Event ID | What it contains |
|---|---|
| 4663 | User, file path, access right used (AccessMask), process, handle ID |
| 4660 | User, handle ID (no file path) |
The 4660 does not say which file was deleted. To find out, you have to match it to the preceding 4663 by handle ID (plus process ID and logon ID).
Also, a 4663 whose AccessMask includes 0x10000 (DELETE) is not necessarily a delete. Windows opens a file with DELETE access for renames and moves, too.
| 4663 AccessMask | 4660 on the same handle | Verdict |
|---|---|---|
includes DELETE (0x10000) | yes | Delete |
includes DELETE (0x10000) | no | Possibly a rename or move |
includes ReadData (0x1) | – | Read |
includes WriteData (0x2) | – | Write |
includes AppendData (0x4) | – | Append |
The "no 4660" case is only possibly a rename or move, because the 4660 may have been overwritten in the log, or fallen just outside the time range you searched. Note also that AccessMask is a combination of bits, and on folders the same bits mean different things (0x1 is "list directory", for example).
Pairing them in PowerShell
Here is the pairing logic in PowerShell. Run it elevated.
# List files deleted in the last 24 hours $since = (Get-Date).AddHours(-24) $maxSeconds = 5 # max gap between the 4663 and the 4660 (a rough guess) $events = Get-WinEvent -FilterHashtable @{ LogName = 'Security'; Id = 4663, 4660; StartTime = $since } | Sort-Object RecordId # oldest first # Turn an event's EventData into a hashtable function Get-EventFields($e) { $fields = @{} ([xml]$e.ToXml()).Event.EventData.Data | ForEach-Object { $fields[$_.Name] = $_.'#text' } $fields } $pending = @{} # key: logon ID + process ID + handle ID, value: 4663 with DELETE $deleted = foreach ($e in $events) { $f = Get-EventFields $e if (-not $f.HandleId -or $f.HandleId -eq '0x0') { continue } $key = '{0}|{1}|{2}' -f $f.SubjectLogonId, $f.ProcessId, $f.HandleId if ($e.Id -eq 4663) { # 4663 is also logged for registry keys etc.; keep files only if ($f.ObjectType -ne 'File' -or -not $f.AccessMask) { continue } if ([Convert]::ToInt64($f.AccessMask, 16) -band 0x10000) { $pending[$key] = [pscustomobject]@{ Time = $e.TimeCreated; Path = $f.ObjectName } } } elseif ($pending.ContainsKey($key)) { # 4660 $open = $pending[$key] $pending.Remove($key) $age = ($e.TimeCreated - $open.Time).TotalSeconds if ($age -ge 0 -and $age -le $maxSeconds) { [pscustomobject]@{ Time = $e.TimeCreated # time of deletion (from the 4660) User = "$($f.SubjectDomainName)\$($f.SubjectUserName)" Path = $open.Path } } } } $deleted | Format-Table -AutoSize The output looks like this (sample values):
Time User Path ---- ---- ---- 12/4/2026 5:42:05 PM CORP\k.sato D:\Share\Projects\Archive2023\Gamma\Gamma_001.docx 12/4/2026 5:42:05 PM CORP\k.sato D:\Share\Projects\Archive2023\Delta\Delta_002.xlsx ... Entries left in $pending at the end are DELETE accesses with no matching 4660. They may be renames or moves, but missing events or incomplete matching can produce the same result.
Note
This is a minimal script to show the idea. Handle IDs get reused, so it matches on logon ID as well and applies a time limit (5 seconds here, as a guess). It will still miss handles that stay open for a long time, and anything where the log has gaps. Watching for the handle close (4658) makes it more accurate, but 4658 requires success auditing for Handle Manipulation, which adds even more volume.
Things you notice once you use it
- For operations over a share, you can't see the app on the user's PC. The process in a 4663 is the server-side process that opened the file. Identify the person by user name.
- Saving an Office file can look like "rename + delete". When saving, Word and Excel may rename the original to a temp file (such as
~WRL0001.tmp), put the new content under the original name, and then delete the temp file. The exact steps vary by app and how the file is saved, but a pile of*.tmpdeletes is usually just saves. - A 4663 has no client IP address. To get it, match the logon ID to the logon (4624) or share access (5140) events.
- Deleting a folder produces one set of events per file inside it. Hundreds of 4663/4660 pairs arrive at once; grouping by user and time makes them easier to read.
3. Finding where a file went: the USN journal
For renames and moves, the 4663 with DELETE tells you something happened, but the Security log does not record the new name or destination. And quite often a "deleted" file was really just dragged into the wrong folder by accident.
That is where the USN journal (change journal) on NTFS and ReFS comes in. It records changes on the volume such as create, rename and delete, and each record contains:
- The file name (name only, not the full path)
- The file ID (file reference number)
- The parent folder's file ID
- The reason (
RENAME_OLD_NAME,RENAME_NEW_NAME,FILE_DELETE, etc.)
A rename leaves two records with the same file ID: the old name (RENAME_OLD_NAME) and the new name (RENAME_NEW_NAME). Resolve the parent file ID of the new-name record to a path, and you have the destination folder.
# Check that D: has a USN journal fsutil usn queryjournal D: # Read the journal and search by file name (show surrounding lines) fsutil usn readjournal D: | Select-String 'Budget_2027' -Context 2, 12 # Resolve a parent folder's file ID to a path fsutil file queryfilenamebyid D: 0x0000000000000000000500000000a1b2 The USN journal, however, does not record who made the change.
- Who and when → 4663 in the Security log
- Where to → the rename record in the USN journal (plus the path resolved from the parent ID)
Only by matching the two on time and original path can you say "CORP\y.ito moved Budget_2027_final.xlsx into the Approved folder at 4:31 PM." There is no shared unique ID between them, so this match is an inference from time and path.
Three caveats:
- The USN journal drops its oldest records once it reaches its size limit. To track renames over time, you need to keep reading it and store the records somewhere else.
- You can resolve a parent ID to a path only if that folder still exists, and you get its path as it is now, which may differ from its path at the time of the change if the folder was renamed or moved since. For folders deleted later, you have to walk through the journal yourself.
- A move to another drive (volume) is a copy plus a delete, so you can't follow it by file ID.
4. What gets painful when you do this by hand
With the steps above, built-in tools are enough to find out who deleted a file. Running it day to day, though, is a lot of work:
- The Security log rolls over in hours or days. By the time someone asks, the events are often gone.
- You have to redo the 4663/4660 pairing, the rename detection and the USN journal matching every time.
- The audit policy and SACLs have to be set on every file server and every folder, with nothing missed.
- Some things, like mass deletions, you want to hear about immediately, not after it's too late.
An example implementation
I implemented the approach above in FileAccessMonitor, a free, open-source (MIT) project I maintain. It reads the Security log continuously, pairs 4663/4660/4659 to classify deletes vs. renames/moves, and fills in destinations from the USN journal, so a file's history can be followed across renames and moves.
There is an online demo with made-up data, if you want to see what the correlated records look like. The examples at the top of the demo page cover the cases in this post:
- "find the deleted folder Archive2023"
- "where Budget_2027.xlsx went"
(The demo starts in Japanese; click EN in the top-right corner to switch to English.)
https://nuts-i77.github.io/FileAccessMonitor/demo/
This is a search for "Archive2023". Deleting the whole folder shows up as a list of deletes, each with user, time and client (all data is fictitious).
This is the history of Budget_2027_final.xlsx: created, renamed (Budget_2027.xlsx → Budget_2027_final.xlsx), moved to another folder (Approved), and read afterwards, all in one timeline.
nuts-i77 / FileAccessMonitor
Who read, changed or deleted a file on your Windows or Samba file server: audit-log collection, web GUI, alerts. No log platform needed.
If you have dealt with this problem differently, I'd like to hear about it in the comments.
Originally written in Japanese: Read the Japanese version on Qiita.
This article was written with the help of AI (drafting and English translation). The technical content comes from my own work building FileAccessMonitor, and I reviewed it before publishing.
References
- Audit File System (Microsoft Learn)
- 4656(S, F): A handle to an object was requested (Microsoft Learn)
- 4663(S): An attempt was made to access an object (Microsoft Learn)
- 4660(S): An object was deleted (Microsoft Learn)
- fsutil usn (Microsoft Learn)
- fsutil file (Microsoft Learn)
- USN_RECORD_V2 structure (Microsoft Learn)
- USN_RECORD_V3 structure (Microsoft Learn)



