Get-ChildItem Cannot Find Path Because It Does Not Exist

后端 未结 3 1665
时光说笑
时光说笑 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)"
    }
    

提交回复
热议问题