Get-ChildItem Cannot Find Path Because It Does Not Exist

后端 未结 3 1666
时光说笑
时光说笑 2021-01-19 01:31

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 perfec

相关标签:
3条回答
  • 2021-01-19 02:02

    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 -not 'IPC$'}){
        Get-ChildItem "\\$($Share.__SERVER)\$($Share.Name)"
    }
    
    0 讨论(0)
  • 2021-01-19 02:03

    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.

    0 讨论(0)
  • 2021-01-19 02:19

    You can list shares by calling:

    net view \\<computername>
    

    source: PowerShell Get List Of Folders Shared

    0 讨论(0)
提交回复
热议问题