The Computer Oracle

list network shares from command prompt

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Lost Meadow

--

Chapters
00:00 Question
00:39 Accepted answer (Score 41)
01:12 Answer 2 (Score 1)
04:54 Thank you

--

Full question
https://superuser.com/questions/274640/l...

Accepted answer links:
[source]: http://ss64.com/nt/net_share.html
[source]: http://ss64.com/nt/net_use.html

Answer 2 links:
[https://social.technet.microsoft.com/For...]: https://social.technet.microsoft.com/For...
[List SMB network shares and usernames they're authenticated under from command prompt]: https://superuser.com/questions/1668781/...
[https://docs.microsoft.com/en-us/powersh...]: https://docs.microsoft.com/en-us/powersh...
[Disconnect from smb share with powershell on Windows 10]: https://superuser.com/questions/1129183/...
[https://social.technet.microsoft.com/For...]: https://social.technet.microsoft.com/For...
[How do I logout of a smb connection on Windows?]: https://superuser.com/questions/1737241/...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#windows #commandline #networkshares

#avk47



ACCEPTED ANSWER

Score 45


Try
net view
to get a list of computers. If you have a computer's name, try
net view \\computer to get a list of shares.

(source)

Once you know what share you're after, you want to go with net use. Map a drive with
net use x: \\computer\share
(replace X: with the drive letter you want to assign).

(source)




ANSWER 2

Score 1


Since this is the first result when I search online for "Windows list network shares command line", I will jot this down:

On Windows 10, when you want to list network shares with net view in Administrator command prompt, by default you get:

C:\WINDOWS\system32>net view
System error 1231 has occurred.

The network location cannot be reached. For information about network troubleshooting, see Windows Help.

I found this post:

Net view - System error 1231 https://social.technet.microsoft.com/Forums/en-US/6f102ed1-8e76-4cb7-8dec-05714466d441/net-view-system-error-1231?forum=win10itpronetworking

I’ve tested the "net view" command in my lab with a Windows10, workgroup machine and met the same problem with you.

Based on my research, it may be caused by the SMBv1 protocol not being installed by default.

So, I went to Control Panel >> Uninstall a program >> Turn Windows Features on or off >> SMB 1.0/CIFS File Sharing Support, then selected SMB 1.0/CIFS Client to turn this feature on. [...]

Why do you need net view? The net view commands depend on the computer browser service, which in turn depends on SMB1. SMB1 is an old, insecure protocol which should not be enabled on any machine with an Internet connection.

Ok, so probably there is something else that can be used from the command line; and I found List SMB network shares and usernames they're authenticated under from command prompt

You can use the PowerShell command Get-SmbConnection (local admin permissions required).

Sample copied from Microsoft: https://docs.microsoft.com/en-us/powershell/module/smbshare/get-smbconnection?view=windowsserver2019-ps

So, I tried Get-SmbConnection in Administrator PowerShell - and it works for me.


Edit: if you want to delete/remove/disconnect a single SMB connection, seems there is no PowerShell command for it:

Disconnect from smb share with powershell on Windows 10 - no answer

How to close SMB connection to remote share? https://social.technet.microsoft.com/Forums/Lync/en-US/ffd8eb2a-9c67-4ab4-adcb-14cfd6a20b43/how-to-close-smb-connection-to-remote-share?forum=winserverpowershell

I can retrieve list of SMB connections using Get-SmbConnection. How can I close those connections? There is no Close-SmbConnection. There is Close-SmbSession but it has to be run on server, not client. The share is not mapped so Romeve-SmbMapping doesn't close the connection. Is there any cmdlet to close SMB connection from client side using PowerShell?

In theory I can run the net use /delete command but net use doesn't always show all SMB connections. It seems to work randomly. Sometimes it shows only mapped shares, sometimes all shares. [...]

So your simple question of how to close SMB connections to a remote share requires a very complex setup of interconnecting settings to work properly.

How do I logout of a smb connection on Windows?

There is a PowerShell command Close-SmbSession, but I have no sessions; only connections: [...]

Otherwise, to close all SMB connections, one strong-arm method is to enter the Services applet and restart the Workstation service. This clears the cached credentials from the SMB connections.