PowerShell

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.

Get-SmbOpenFile

Open Windows PowerShell an run

Get-SmbOpenFile | Format-List

1.PNG

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

2.PNG

Get-SmbSession

To show all connections run

Get-SmbSession

1.PNG

Closing open files

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

Unbenannt.PNG

For this file, it’s all over now 😉

Close-SmbOpenFile -FileId 120259084297

Categories: PowerShell

Tagged as: ,

5 replies »

Leave a reply to panzerbjrn Cancel reply

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