How to Inspect and Close Locked Network Files in Windows 11 Using PowerShell Get-SmbOpenFile

In collaborative office environments and home lab networks where folders and drives are shared across local networks via the Server Message Block (SMB) protocol, users frequently encounter frustrating file access collisions. Attempting to rename, move, overwrite, or delete a shared spreadsheet, CAD file, or database often yields the error: “The action can’t be completed because the file is open in another program.” While restarting the host computer clears locks, rebooting disrupts all other connected network users. Windows provides a dedicated set of Server Message Block cmdlets in PowerShell—centred around Get-SmbOpenFile and Close-SmbOpenFile—that allows administrators to audit active file handles and selectively terminate locks without system disruption.

Understanding SMB File Locks and the SmbShare Module

When a remote client on your local area network (LAN) accesses a shared directory on your Windows 11 machine or Windows Server, the SMB server daemon (lanmanserver) creates an open file handle. This handle tracks:

  • FileId: A unique 64-bit numerical identifier assigned to the open file instance.
  • Path: The exact local filesystem path of the shared file or directory (e.g. D:\Shares\Projects\Budget.xlsx).
  • SessionId: The network session ID representing the remote client connection.
  • ClientComputerIP: The IPv4 or IPv6 address of the remote device maintaining the lock.
  • ClientUserName: The domain or local user account currently accessing the resource.
  • Permissions: The access mask granted to the client (such as Read, Write, or Delete).

The native SmbShare PowerShell module allows administrators to inspect this table in real time and break deadlocks cleanly.

Querying Active Open Network Files with Get-SmbOpenFile

Because querying SMB file handles interrogates low-level file system server structures, launch PowerShell with elevated privileges: press Win + X and select Terminal (Admin) or PowerShell (Admin).

To list every open network file currently accessed across your shared folders, execute:

Get-SmbOpenFile

If numerous files are open, condense and organise the output into an aligned table isolating essential identifiers:

Get-SmbOpenFile | Format-Table FileId, ClientComputerIP, ClientUserName, Path -AutoSize

Filtering for a Specific Locked File or Folder

When investigating a specific file that cannot be modified, pipe the results into Where-Object to search for the filename or path substring:

Get-SmbOpenFile | Where-Object { $_.Path -like "*Budget.xlsx*" }

The output provides the exact FileId maintaining the lock, alongside the IP address and user account of the colleague whose machine left the file open.

How to Forcibly Close an SMB File Handle

Once you have identified the offending FileId, you can terminate the network lock instantly using Close-SmbOpenFile. This command severs the client’s file handle without terminating their general network session or disconnecting other shared resources.

Closing by FileId

Pass the unique numerical identifier obtained from the query:

Close-SmbOpenFile -FileId 123456789 -Force

Adding the -Force parameter bypasses interactive confirmation prompts, which is essential when executing automated administration scripts.

Closing All File Handles for a Specific Path

If multiple clients or multiple threads have locks on the same file, you can close all associated handles simultaneously by piping the query directly into Close-SmbOpenFile:

Get-SmbOpenFile | Where-Object { $_.Path -like "*Budget.xlsx*" } | Close-SmbOpenFile -Force

Immediately after executing this command, the file lock is released on the underlying NTFS/ReFS filesystem, allowing you to edit, move, or archive the document without waiting for the remote client to close their application.

Closing All File Handles Maintained by a Specific User or Client IP

If an employee leaves the office with their laptop suspended or if an automated client crashes while holding dozens of open file handles across shared directories, you can clear all locks tied to that user or IP address:

Get-SmbOpenFile | Where-Object { $_.ClientComputerIP -eq "192.168.1.145" } | Close-SmbOpenFile -Force

This command clears only the orphaned file handles associated with that specific workstation, preserving operational stability across the rest of your networked infrastructure.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.