6

I'm working on a script to get my ACLs for all of the shares in my network. I have three separate UNC paths that I am running this on. Two of the three are working perfectly, returning all child items and permissions and such. However, the third UNC path is returning the following error:

Get-ChildItem : Cannot find path '\\storagesrvr' because it does not exist.

I have verified that the location is available by using Explorer. What I find interesting is that if I use GCI on any of the sub-shares of that path, it works. What could possibly be preventing GCI from detecting the root of the share?

EDIT (as requested from comments): The other two shares that I had no issues with were named like \\networkpath\share. But because I was only looking at the root, GCI was not working.

3
  • 1
    The root of a remote device namespace is not a directory - \\computer is not even a fully valid UNC path according to the spec. Retrieve share names from the Win32_Share wmi class on the remote machine and runt Get-ChildItem against them one by one Commented Feb 28, 2017 at 15:48
  • 1
    I think this is relevant too (PowerShell Gotcha 'UNC paths and Providers'): powershell.org/2014/02/20/… Commented Feb 28, 2017 at 15:49
  • 1
    Check out PowerShell Get List Of Folders Shared for answers on how to get a list of network shares Commented Feb 28, 2017 at 15:52

3 Answers 3

7

As I mentioned in the comments \\computername is only a partial UNC path (check the UNC grammar in the [MS-DTYP] Windows Data Type specification).

Explorer "knows" this, and so it does some black magic in the background to allow you to browse the shares on the remote computer.

You can emulate this, by querying the Win32_Share WMI instances on the remote machine:

foreach($Share in Get-WmiObject Win32_Share |?{$_.Name -ne 'IPC$'}){ Get-ChildItem "\\$($Share.__SERVER)\$($Share.Name)" } 
Sign up to request clarification or add additional context in comments.

1 Comment

Just came across this to correct the "-not" part to "-ne" to make above run. Thanks
2

You can list shares by calling:

net view \\<computername> 

source: PowerShell Get List Of Folders Shared

3 Comments

this is not a powershell answer, this get-WmiObject -class Win32_Share -computer dc1.krypted.com is probably what you meant?
True, however it works with powershell and unlike get-wmiobject doesn't require extra privileges or protocols to be enabled.
Fair enough, you have my up vote sir. Might want to add it to the original answer you made because it does raise a valid point. Net view will work in most cases on a windows domain with shares on a computer because they're required to have printer and sharing enabled, which is what net view relies on to enumerate them.
1

The error message is literally correct. \\storageserver is not a path. It is two backslashes followed by a computer name.

Append a share name to it, and it becomes a path; e.g. \\storageserver\sharename.

2 Comments

Okay, but shouldn't adding a backslash and a wildcard to the end find all of the shares?
No. (Unfortunately, wishful thinking does not cause features to spring into existence.)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.