List SMB network shares and usernames they’re authenticated under from command prompt

command linenetwork-sharessambawindows 10

As noted in list network shares from command prompt, in Command Prompt (cmd.exe), I can use the following command to list available network shares:

net view \\computer

In my case, this gives something like:

C:\Users\user> net view \\COMPUTERNAME
Shared resources at \\COMPUTERNAME

TEST-FILE

Share name             Type  Used as  Comment

-------------------------------------------------------------------------------
archive                Disk           Fileserver
myfiles                Disk           Fileserver
MyShare                Disk  (UNC)
...

However, if you type net use and press enter, you should get a list of all network shares you're connected to currently. – and in my case, I get:

$ net use
New connections will be remembered.


Status       Local     Remote                    Network

-------------------------------------------------------------------------------
OK                     \\COMPUTERNAME\MyShare      Microsoft Windows Network
OK                     \\COMPUTERNAME\IPC$         Microsoft Windows Network
The command completed successfully.

Usually, whenever I want to access \\COMPUTERNAME and I am not authenticated, I need to authenticate with a login and password.

So, if the authentication dialog does not show, that means I am already logged in – but I cannot tell what username I am logged in as.

Is there any way to see from the command line, which login have I authenticated with, to gain access to a \\COMPUTERNAME share?

Best Answer

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

I have tested this command on a Windows 10 client and it shows all my network connections similar like the following sample output.

PS C:\>Get-SmbConnection
ServerName          ShareName           UserName             Credential           Dialect             NumOpens 
----------          ---------           --------             ----------           -------             -------- 
Contoso-FS1         VMS5                Contoso\Contoso-HV1$ Contoso\Contoso-HV1$ 3.00                1 
Contoso-FS1         VMS5                NT VIRTUAL MACHI...  Contoso\Contoso-HV1$ 3.00                3 
Contoso-FS          VMS1                Contoso\Contoso-HV1$ Contoso\Contoso-HV1$ 3.00                1 
Contoso-FS          VMS1                NT VIRTUAL MACHI...  Contoso\Contoso-HV1$ 3.00                5 
Contoso-SO          VMS3                Contoso\Contoso-HV1$ Contoso\Contoso-HV1$ 3.00                1 
Contoso-SO          VMS3                NT VIRTUAL MACHI...  Contoso\Contoso-HV1$ 3.00                1 
Contoso-SO          VMS3                NT VIRTUAL MACHI...  Contoso\Contoso-HV1$ 3.00                2

Note: I recognized that this only works for shares where the credentials are not been saved. For shares where you have saved the credentials instead your current logged-in user-account is shown. Therefore for connections using saved connections you have to check Windows Credential Manager what username is used for establishing the connection. Tested on Windows 10 20H2 joined a Windows domain.

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