Question

I am trying to use Powershell to get file names from a network folder. 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.

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.

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. Any thoughts or suggestions would be appreciated.

$source = Get-ChildItem "\\networkdrive\Release\Installs\2012.1.2.3\"
Was it helpful?

Solution

I found another way to do this but it does use .NET classes so, strictly speaking, it doesn't fully answer my own question. However, it does get the job done, so here it is:

$source = [System.IO.Directory]::GetFiles("\\networkdrive\Release\Installs\2012.1.2.3", "*.exe")

OTHER TIPS

$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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top