且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

用于get-childItem的PowerShell多线程

更新时间:2022-03-27 05:30:06

计算机上是否有可用的PowerShell 3?如果这样做,则可以创建一个工作流,该工作流采用文件夹的数组列表.我没有执行此操作的摘要,但是如果您有兴趣,我可以提出一些建议.

Do you have PowerShell 3 available on the machine? If you do, then you can create a Workflow that takes an arraylist of folders. I do not have a snippet for doing this, but if you are interested I can come up with something.

编辑(在下面添加伪代码):

Edit (adding pseudo code below):

workflow GetFileInformation
{
    param([System.IO.FileSystemInfo[]] $folders)

    foreach -parallel ($folder in $folders)
    {
        inlinescript 
        {
            $files = GCI -LiteralPath $folder.FullName -File
            # Here you will have an Array of System.IO.FileSystemInfo
            # I do not know what you want to do from here, 
            # but the caller will have no visibility of this object 
            # since it is on a separate thread.
            # but you can write the results to a file or database.
            # Hope this helps some.
        }
    }
}

$dir = GCI C:\ -Directory -Recurse
GetFileInformation $dir