PowerShell: Find and close open files (SMB Share)

What files are open? Who is connected to the file server? Those informations might be useful for backing up, maintaining or restarting your file server. To accomplish this task run Get-SmbOpenFile to show the path of the share, the open files and the connected user.


Open Windows PowerShell an run

Get-SmbOpenFile | Format-List


To show only connections for a specific file share run Get-SmbOpenFile with Where-Object.

Get-SmbOpenFile | Where-Object Path -eq "C:\Data\" | Format-List



To show all connections run



Closing open files

My next task is to close those open files. First, I look for the FileId.


For this file, it’s all over now 😉

Close-SmbOpenFile -FileId 120259084297

Categories: PowerShell

Tagged as: ,

5 replies »

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.