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: ,

1 reply »

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 )

Google+ photo

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

Twitter picture

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

Facebook photo

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

w

Connecting to %s