Get-ChildItem 找不到路径,因为它不存在 [英] Get-ChildItem Cannot Find Path Because It Does Not Exist

查看:149
本文介绍了Get-ChildItem 找不到路径,因为它不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个脚本来获取我网络中所有共享的 ACL.我有三个单独的 UNC 路径来运行它.三个中的两个工作正常,返回所有子项和权限等.但是,第三个 UNC 路径返回以下错误:

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 : 找不到路径\\storagesrvr",因为它不存在.

我已使用资源管理器验证该位置可用.我觉得有趣的是,如果我在该路径的任何子共享上使用 GCI,它就可以工作.什么可能阻止 GCI 检测共享的根目录?

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?

编辑(根据评论的要求):我没有问题的另外两个共享被命名为 \\networkpath\share.但是因为我只看根,所以 GCI 不起作用.

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.

推荐答案

正如我在评论中提到的 \\computername 只是一个部分 UNC 路径(检查 [MS-DTYP] Windows 数据类型规范).

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知道"这一点,因此它会在后台执行一些黑魔法以允许您浏览远程计算机上的共享.

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

您可以通过查询远程计算机上的 Win32_Share WMI 实例来模拟这一点:

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)"
}

这篇关于Get-ChildItem 找不到路径,因为它不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆