I'm trying to disconnect a smb share with a Powershell command in Windows 10:
net use * /delete
However, this command does not work, because the share is not shown with net use
. The output is There are no entries in the list.
Get-SmbConnection
is showing the results I'd expect,
ServerName ShareName UserName Credential Dialect NumOpens
---------- --------- -------- ---------- ------- --------
FILESERVER extra xxx\xxxxx xxx\xxxxx 3.0 1
FILESERVER home xxx\xxxxx xxx\xxxxx 3.0 1
FILESERVER IPC$ xxx\xxxxx xxx\xxxxx 3.0 0
FILESERVER public xxx\xxxxx xxx\xxxxx 3.0 2
But I do not know how to disconnect a share with this information.
The reason for my question: I want to write a batch script which disconnects all network shares from a PC after log off (e.g. Win+L keys). On Windows 7 and 8 I use the mentioned net use * /delete
command, which does not work on Windows 10, as shown above.
The SMB shares are accessible with the GUI (Explorer -> Network …) and I can save, change and delete files on them. But the share is not mapped to a drive letter.
Following is a bit output for stuff that does not help, but it seems my question is still not clear enough:
Get-SmbConnection
: see above, I want to close these!
Get-SmbSession
: No output.
Get-SmbMapping
: No output.
Get-SmbShare
:
Name ScopeName Path Description
---- --------- ---- -----------
ADMIN$ * C:\WINDOWS Remoteverwaltung
C$ * C:\ Standardfreigabe
IPC$ * Remote-IPC
print$ * C:\WINDOWS\system32\spool\drivers Druckertreiber
Best Answer
Try
Remove-SmbMapping
. Assuming you're on the client, it looks like this is the one you want to use. You can probably pipe results fromGet-SMBConnection
toRemove-SmbMapping