列出UNC根文件夹中的文件夹和文件 [英] List folders and files in a UNC root folder
问题描述
我正在尝试从UNC路径名的根目录中获取文件夹和文件。我正在使用 Get-ChildItem
。
I am trying to get folders and files from the root of a UNC path name. I am using Get-ChildItem
.
我可以通过UNC路径从子文件夹中获取结果,但不能根文件夹。如果从命令行运行命令 Get-ChildItem \\sf1\user1
,则返回结果。
I can get results from a subfolder via the UNC path, but not the root folder. If run the command Get-ChildItem \\sf1\user1
from the command line, results are returned.
Directory: \\sf1\user1
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 11/14/2013 3:40 PM 1.ISGROUP
当我尝试从命令行执行 Get-ChildItem \\sf1
时遇到错误。
When I try to execute Get-ChildItem \\sf1
from the command line I get errors.
Get-ChildItem : Cannot find path '\\sf1' because it does not exist.
At line:1 char:1
+ Get-ChildItem \\sf1
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (\\sf1:String) [Get-ChildItem], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
关于如何从UNC路径的根中获取文件夹和文件的任何建议吗?
Any suggestions on how to get folders and files from the root of a UNC path?
推荐答案
As Mathias指出,有效的UNC路径至少包含服务器和共享( \\servername\sharename
),还可以选择包含子文件夹( \ \\服务器名\共享名\子文件夹
)。您不能直接从服务器列出文件/文件夹。如果要枚举远程服务器上的共享,请使用 net视图\\servername
(如Anthony Stringer所述)。请注意,这将仅列出可见份额。如果您还想列出隐藏的共享(名称以 $
结尾的共享),则需要在 net share
上运行服务器
As Mathias pointed out, a valid UNC path consists of at least server and share (\\servername\sharename
), optionally subfolders too (\\servername\sharename\sub\folder
). You cannot list files/folders directly from a server. If you want to enumerate shares on the remote server use net view \\servername
(as Anthony Stringer mentioned). Note that this will list only visible shares. If you also want to list hidden shares (shares whose name ends with a $
) you need to run net share
on the server
Invoke-Command -Computer servername -ScriptBlock { & net share }
或使用WMI
Get-WmiObject -Computer servername -Class Win32_Share
这篇关于列出UNC根文件夹中的文件夹和文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!