Windows Server 2008 Script to close share sessions

windows-server-2008

In the Share and Storage Managment console, you are able to close all session for a particular share by highlighting the share, clicking manage sessions, and closing your connections form there.

Is there a way to perform this same task via a script. We have an end user that is unable to eject removable media because there are open sessions on the share and this is the only way we have found to release the connections.

Ideally, providing the end user with a script that does this behind the scenes would be best.

Anyone have any suggestions?

-Brian

Best Answer

FOR ALL SHARES

net session \\computername /delete (where computername is the name of the computer connected...which you can see via just net session)

or if you want to disconnect everyone:

net session /delete

FOR A SINGLE SHARE VIA VBSCRIPT

Set objConnection = GetObject("WinNT://SERVER/SHARE")
Set colSessions = objConnection.Sessions

For Each objSession in colSessions
    colSessions.Remove(objSession.Name)
Next

I'm not aware of a Powershell cmdlet that works on 2008 to close an SMB session, but maybe there is one.

Related Topic