7

Ok, I have seen: Change working directory to network share - however, it does not seem to work for me on Windows 10.

At work, I have a network share, let's say, at local IP address 20.0.0.1; so, first I go to a Windows Explorer window, type there \\20.0.0.1\, I get asked for a login and password; when I enter my credentials, I get a directory listing, no problem. (and I even get \\20.0.0.1\ as a node under Network in the tree view pane on the left of the Windows Explorer window.)

So, now I open Powershell as administrator, and try this:

PS C:\WINDOWS\system32> cd \\20.0.0.1\
cd : Cannot find path '\\20.0.0.1\' because it does not exist.
At line:1 char:1
+ cd \\20.0.0.1\
+ ~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (\\20.0.0.1\:String) [Set-Location], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand

Same for cmd.exe, ran as Administrator:

C:\WINDOWS\system32>pushd \\20.0.0.1\
The network name cannot be found.

Net use does not work either:

C:\WINDOWS\system32>net use Y: \\20.0.0.1\
System error 67 has occurred.

The network name cannot be found.

... and yet, the server is fully pingable:

C:\WINDOWS\system32>ping 20.0.0.1

Pinging 20.0.0.1 with 32 bytes of data:
Reply from 20.0.0.1: bytes=32 time<1ms TTL=64
Reply from 20.0.0.1: bytes=32 time<1ms TTL=64

Ping statistics for 20.0.0.1:
    Packets: Sent = 2, Received = 2, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms
Control-C
^C

How can I cd into this network share from a terminal (either cmd, or Powershell)?

sdbbs
  • 1,127
  • 4
  • 16
  • 22
  • 2
    `20.0.0.1` is only the machine, you need to tell the command where to go on the machine, e.g if it's a windows computer `\\20.0.0.1\c$`. also, only PowerShell supports UNC Path in `cd` – SimonS Nov 04 '19 at 12:09
  • Many thanks @SimonS - I was persuaded that `\\20.0.0.1\\`` would mount the "root" folder (that is, the "folder" that contains the collection of folders that I see, when I enter `\\20.0.0.1\\`` in Windows Explorer)! Feel free to post this as an answer, I'll accept it ... – sdbbs Nov 04 '19 at 12:13
  • The folders you see if you enter `\\20.0.0.1` are the shares that are enabled on that machine, excluding the standard ones like `c$`. So it is not a real folder, it's only there to help you navigate through windows explorer / networks – SimonS Nov 04 '19 at 12:34

2 Answers2

12

1: You've got the syntax wrong: \\servername\ specifies a server, not a UNC-PATH.
You need to use \\servername\sharename as a minimum.
2: You can't do this with the command-prompt. You must map a network drive to it and use the drive letter in CMD.exe. It will work in PowerShell.

Run5k
  • 15,723
  • 24
  • 49
  • 63
Tonny
  • 29,601
  • 7
  • 52
  • 84
  • 2
    Thanks for that, @Tonny - just to note, the question I linked to in the OP already notes you cannot `cd` into a network share using `cmd.exe` - which is why it recommends `pushd` for `cmd.exe` instead (also what I used in my OP too) – sdbbs Nov 04 '19 at 12:16
  • 2
    Pushd won't do it either: Unless command-extensions are enabled: In that case it will allocate a drive-letter, map the share and then CD to that drive-letter. It will NOT really cd to the UNC-path. – Tonny Nov 04 '19 at 12:19
6

What about a PowerShell Core solution? I was successfull using

cd Microsoft.PowerShell.Core\FileSystem::\\servername\sharename
Daniel
  • 160
  • 1
  • 5
  • For a chance please: Have you managed this only with PS? I tried your solution which worked but only for 50%. I have a computer in the network. When I executed the command, it tried for a while and then resulted in an error stating that the path cannot be found. Then, I have entered the path to the explorer, filled in the prompt for credentials (but I haven't mounted it, just accessed it), but then, the PS command worked when I tried. Is there any PS way to do even the accessing/credentials stuff directly by command? I work on a computer, where I have terminal (PS) access only. Thanks! – Zorak Sep 26 '22 at 14:28
  • @zorak Adding credentials for the share can be done with CMD and with PowerShell. I can't recall the PowerShell version from the top of my head and I don't have a Windows system nearby. But in CMD you can just add the parameter "/user:youryuserid" to the NET USE command and it will prompt you for the password. Like "net use x: \\myserver\myshare /user:zorak" – Tonny Sep 30 '22 at 08:52