7

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?

4
  • 1
    If you currently don't have access and are getting an auth prompt, doesn't that actually mean you're not authenticated to those shares at all? (Or, to the server as a whole, really.) Commented Aug 11, 2021 at 12:08
  • Thanks @user1686 - indeed, if I do get a prompt, that means I'm not authenticated; apologies, the post was a bit unclear, so I've edited it. My problem here is the opposite - I had logged in previously, so I do not get a dialog prompt asking me for username:password - but I had forgotten which username I had logged in as. So what could I use, to find out which username I had logged in as?
    – sdbbs
    Commented Aug 12, 2021 at 8:36
  • 2
    If you have saved your credentials then you can look them up in Windows Credential Manager
    – Robert
    Commented Aug 12, 2021 at 10:59
  • Thanks @Robert - I typically do not save my credential (so then, if I suspect I'm logged in under the wrong login, I at least have the option to reboot); however - good to keep Windows Credential Manager in mind.
    – sdbbs
    Commented Aug 12, 2021 at 11:24

1 Answer 1

7

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .