Australian cloud for business software — built and run in Sydney since 2002

NetLeverage
NetLeverage

File in use on a Windows file share: find who has it open with Get-SmbOpenFile, and close it safely

Technical article
Troubleshooting

About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.

A file that cannot be changed, renamed or deleted on a share is held open by something else. Windows defines the failure as system error 32, "The process cannot access the file because it is being used by another process." On the file server, Get-SmbOpenFile lists every file held open by an SMB client, with the user, the client computer and a file ID. Ask the person to save and close first. Only if they cannot be reached should you use Close-SmbOpenFile, which Microsoft warns "can cause data loss to the client".

What the error means

Error 32 is ERROR_SHARING_VIOLATION. A program asked for a file in a way that conflicts with how another program already holds it. Windows does not say who the other program is, which is why you ask the server.

An SMB file server keeps a record of the sessions that clients have established and the files each session holds open. Microsoft describes Get-SmbOpenFile as retrieving "basic information about the files that are open on behalf of the clients of the Server Message Block (SMB) server". The same family includes Get-SmbSession, which lists the sessions, and Close-SmbOpenFile, which "forcibly closes a file that is open by one of the clients".

Get-SmbOpenFile returns one row per handle. A single file can appear more than once. Fields documented in Microsoft's example include ClientComputerName, ClientUserName, FileId, SessionId, Path (the path on the server), ShareRelativePath (the path inside the share), ScopeName, ClusterNodeName, Locks and Permissions.

The SMB cmdlets show only files held open by SMB clients. A program running on the server itself, such as a backup agent or an antivirus scanner, does not appear there. The openfiles command has a separate setting for that case, covered below.

Likely causes

Cause What you see How to confirm
A user has the file open from their own computer A row with that user and client Get-SmbOpenFile filtered on the file name
A client that has gone idle or lost its network still holds the handle A row whose session has a high SecondsIdle Get-SmbSession for the session shows SecondsIdle and NumOpens
A shared file is held by a service account or a scheduled task from another server The ClientUserName is a service account, or a computer account (a name ending in $) The client name and user in the open-file row
A process on the file server itself holds the file No row in Get-SmbOpenFile, yet the file is in use Local handle tracking with openfiles /local (see Fix)
The share belongs to a clustered file server Rows appear only for the scope or node you queried Query with -ScopeName or -ClusterNodeName

Prove the cause before changing anything

Run these on the file server, in an elevated PowerShell session. They only read.

List every file held open, then narrow to the file name. Microsoft's example filters on a file name extension through ShareRelativePath; the same form works for part of a file name:

Get-SmbOpenFile | Where-Object -Property ShareRelativePath -Match "Budget"

The default view shows FileId, SessionId, Path, ShareRelativePath, ClientComputerName and ClientUserName. To see everything about one handle, use Get-SmbOpenFile -FileId <id> | Select-Object -Property *. You can also filter directly with -ClientComputerName and -ClientUserName.

For one session, read its age and how many files it holds:

Get-SmbSession -SessionId <SessionId>

The output includes NumOpens. With Select-Object -Property * it also shows SecondsIdle, SecondsExists and Dialect. A session idle for hours that still holds files points to a client that has left without releasing them, or to a user who walked away with the file open.

The openfiles command offers a second view. openfiles /query "queries and displays all open files", and /fo list /v gives detailed output. Microsoft's page documents /s <system> for a remote computer.

To see files held by programs on the server itself, Microsoft documents the "Maintain Objects List" global flag, which "tracks local file handles", and states that openfiles /local with no argument shows its current status. By default it is disabled, with the message "INFO: The system global flag 'maintain objects list' is currently disabled." Reading the status changes nothing.

Fix

Start with the gentlest option and move on only if it fails.

1. Ask the person to save and close. You now know who and from which computer. A phone call costs less than data loss.

2. If the handle belongs to a session that has plainly gone, close that handle only. First rehearse. Close-SmbOpenFile supports -WhatIf, which "shows what would happen if the cmdlet runs. The cmdlet is not run":

Close-SmbOpenFile -FileId <FileId> -WhatIf

Disruptive step: Close-SmbOpenFile forcibly closes the file for that client. Microsoft states it "can cause data loss to the client for which the file is being closed if the client has not flushed all of the file modifications back to the server". The client's application may show an error or an inconsistent document, and unsaved edits can be lost. There is no way back for changes that never reached the server. To back out the effect on the client, the user reopens the file; recovering lost edits depends on that application's autosave.

Close-SmbOpenFile -FileId <FileId>

Without -Force, PowerShell asks you to confirm each file. Microsoft's example for -Force closes every file matching a pattern "without user confirmation". Do not use it with a wide filter on a busy server.

3. Close by session only when every file in it is yours to close.

Disruptive step: Close-SmbOpenFile -SessionId <SessionId> closes all files held by that session. Microsoft's example confirms each file in turn. Check NumOpens first, and use -WhatIf. No way back for unsaved work in any of them.

4. The openfiles alternative. openfiles /disconnect /id <id> "disconnects open files by the specified file ID", and the ID comes from openfiles /query. The page says it disconnects files "opened remotely through a shared folder". Prefer the SMB cmdlets, because -WhatIf is documented for them.

Disruptive step: openfiles /disconnect /id <id> force-closes that open file for the client that holds it. Impact: the client's application may show an error, and edits not yet flushed to the server can be lost, with no preview step as -WhatIf gives. There is no way back for changes that never reached the server; the user reopens the file, and recovery of lost edits depends on that application's autosave. Check the ID against the openfiles /query output for the right user and file before running it.

5. A local process holds the file.

Risk: openfiles /local on enables the "Maintain Objects List" global flag. Microsoft says the change "doesn't take effect until you restart the system" and that enabling it "might slow down your system". Switch it off again with openfiles /local off (also effective after a restart). Plan a restart window before you enable it on a production server.

Once the flag is on and the system restarted, local handles can be listed and the owning program found and stopped through its own tools. Stopping that program is a separate decision with its own risk.

Confirm the fix

Run the same Get-SmbOpenFile filter again. The row for the file should be gone. Ask the user who needed the file to open it, edit and save it. If the row returns immediately, the user's computer reopened the handle; look at the client rather than closing it again.

Example (illustrative): on fs01, CONTOSO\mlee reports that Budget FY27.xlsx cannot be saved by a colleague. Get-SmbOpenFile | Where-Object -Property ShareRelativePath -Match "Budget" returns one row: FileId 4123456789012, SessionId 4123456789001, ClientComputerName 10.0.20.57, ClientUserName CONTOSO\mlee. Get-SmbSession -SessionId 4123456789001 shows NumOpens of 1 and SecondsIdle of 7,200. That is 120 minutes, or 2 hours. The technician phones Ms Lee, whose laptop is asleep in a bag. Having confirmed with -WhatIf that only that one handle would close, the technician runs Close-SmbOpenFile -FileId 4123456789012. The colleague can now save, and Ms Lee is told that edits made in the last two hours but never saved to the share may not be there.

What to watch afterwards

  • Note whether the same user or the same client appears again and again. Repeated stale handles point to sleeping laptops or unstable networks.
  • If the same file is held by a service account, find out what the job does and when.
  • Keep a record of every forced close: file, user, time and who authorised it.
  • If shared editing is the real need, hosted file storage is an alternative to a file server, and a separate subject from this fault.

Risks and limits

These commands have not been run or lab-tested.

The cmdlet pages are published for Windows Server 2016, 2019, 2022 and 2025 and show no date. They do not describe how every application reacts to a forced close, and they do not describe exactly what appears in the Windows file-in-use dialogue boxes. The openfiles page does not say whether /query lists local handles before the global flag is enabled; read the output on your own server and treat an empty result as inconclusive.

Do not run Close-SmbOpenFile with -Force to clear a share before maintenance without warning users. Tell them first.

Sources

  • Get-SmbOpenFile — Microsoft Learn, date not shown, accessed 18 November 2026
  • Close-SmbOpenFile — Microsoft Learn, date not shown, accessed 18 November 2026
  • Get-SmbSession — Microsoft Learn, date not shown, accessed 18 November 2026
  • openfiles — Microsoft Learn, page dated 2023-02-03, accessed 18 November 2026
  • System Error Codes (0-499) — Microsoft Learn, page dated 2025-07-14, accessed 18 November 2026