简体   繁体   English

使用Powershell从网络文件夹中获取文件名

[英]Using Powershell to get just the file names from a network folder

I am trying to use Powershell to get file names from a network folder. 我正在尝试使用Powershell从网络文件夹中获取文件名。 My understanding of Get-ChildItems (please correct me if I'm wrong on this) is that the cmdlet is trying to download the entire object which, in this case, is a series of product installers ranging in size from 25MB to 315MB per file. 我对Get-ChildItems的理解(如果我错了,请纠正我)是cmdlet正在尝试下载整个对象,在这种情况下,它是一系列产品安装程序,大小从每个文件25MB到315MB 。

The purpose of my script is to create a menu for the user to choose which file they would like to download. 我的脚本的目的是为用户创建一个菜单,以选择他们想要下载的文件。 Everything works, except it takes 30+ minutes to populate the menu, which is obviously unacceptable. 一切正常,除了填充菜单需要30多分钟,这显然是不可接受的。

I am thinking I may need to incorporate some .NET classes to make this work, but if I can do it purely with Powershell it would be nice. 我想我可能需要合并一些.NET类来实现这个功能,但如果我能用纯粹的Powershell做它,那就太好了。 Any thoughts or suggestions would be appreciated. 任何想法或建议将不胜感激。

$source = Get-ChildItem "\\networkdrive\Release\Installs\2012.1.2.3\"

I found another way to do this but it does use .NET classes so, strictly speaking, it doesn't fully answer my own question. 我发现了另一种方法,但它确实使用.NET类,所以严格来说,它并没有完全回答我自己的问题。 However, it does get the job done, so here it is: 但是,它确实完成了工作,所以这里是:

$source = [System.IO.Directory]::GetFiles("\\networkdrive\Release\Installs\2012.1.2.3", "*.exe")
$source = Get-ChildItem "\\networkdrive\Release\Installs\2012.1.2.3\" | Where-Object{-Not $_.PsIsContainer}

That will get just the files, but I don't think there is a lot you can do about the time that it takes. 这将只获得文件,但我不认为你可以做很多时间。 In theory you could run it remotely on the server where the share lives. 从理论上讲,您可以在共享所在的服务器上远程运行它。 That would be faster. 那会更快。 Not sure if that is an option in your environment or not though. 不确定这是否是您环境中的选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM