Find who is writing to a file share
List open files and sessions on a Windows file server by client and user, and know what open handles can and cannot tell you.
Before you start
- Where: an elevated PowerShell on the file server itself. On a failover cluster file server, run it on the node that owns the file server role.
- Why you are looking. If files are being renamed or encrypted right now, this page helps you find the client, but the response is R1 Ransomware: isolate that client first.
- For history, not just “now”: file auditing must already be on. Event 4663 is only written if the folder’s audit settings (SACL) ask for it. Turning auditing on today does not show what happened yesterday.
Steps
1. Which clients have the most files open
Get-SmbOpenFile | Group-Object ClientComputerName | Sort-Object Count -Descending | Select-Object Count, Name
Source: Get-SmbOpenFile, Microsoft Learn
One client with far more open files than everyone else is your first lead.
2. Open files under one folder
Get-SmbOpenFile | Where-Object Path -like 'D:\Shares\Finance\*' | Sort-Object ClientComputerName | Format-Table ClientComputerName, ClientUserName, Path
Source: Get-SmbOpenFile, Microsoft Learn
Use the server’s local path, not the share name.
3. Sessions: who is connected, from where
Get-SmbSession | Sort-Object NumOpens -Descending | Format-Table ClientComputerName, ClientUserName, NumOpens
Source: Get-SmbSession, Microsoft Learn
4. If auditing is on: who actually wrote
Get-WinEvent -FilterHashtable @{ LogName = 'Security'; Id = 4663; StartTime = (Get-Date).AddHours(-1) } -MaxEvents 200
Source: Get-WinEvent and Event 4663, Microsoft Learn
Microsoft: 4663 “shows that access right was used instead of just requested”. Each event names the account, the object and the access used.
What good and bad look like
- Good: the open files match what people are doing (the accounts team has the ledger open, the scanner writes into its folder).
- Bad: one client or account holds hundreds of files across many folders, or audit events show one account writing and renaming files quickly. Treat it as a possible ransomware case and go to R1.
- Unclear: a service account from a server holds many files. That is often a backup or sync job. Check its schedule before you suspect it.
Traps
- Open is not writing. An open handle shows a file is open, not what is being done to it. Only auditing (step 4) shows writes.
- Closing files is a separate decision.
Close-SmbOpenFileforces a file closed and unsaved changes are lost. It does not stop a client that is still connected, which can simply reopen the file. - Stopping the wrong thing. In a ransomware case, isolate the client machine from the network. Do not shut down the file server; you may need its state for the investigation.
- NAT and terminal servers. Many users can appear behind one client address. Use the user name column as well.
Undo
Steps 1 to 4 only read. If someone decided to close a file with Close-SmbOpenFile (Microsoft Learn), that cannot be undone: the user’s unsaved changes are gone.
Record it
Example included. The row marked Example is made up to show the format. Delete it and add your own rows.
| Date and time | Why we looked | Client, user | Files open | Audit evidence | Action | Initials |
|---|---|---|---|---|---|---|
| Example: 2026-12-08 10:20 | Helpdesk: “share is slow” | PC-0142, jdoe | 12 | Not needed | None, normal Excel use | AB |