用于get-childItem的PowerShell多线程 [英] PowerShell multithreading for get-childItem

查看:98
本文介绍了用于get-childItem的PowerShell多线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要扫描CIFShare并获取共享中所有文件和文件夹的文件属性和ACL属性.我知道get-chilItem中有-recursive选项,但是如果共享很大,使用-recursive选项确实很耗时.我知道这可以通过多线程实现.

I have a requirement of scanning a CIFShare and get the file properties and ACL properties of all the files and folders in the share.I know there is an option of -recursive in get-chilItem but in case of very large shares, using the -recursive option is really time consuming.I know this can be achieved with multithreading.

假设层次结构如下:-

Root
Root\FolderA
Root\FolderA\FolderA1\FolderA2\FolderA3\FolderA3\FolderA4
Root\FolderB\..
..

我已经管理了一个脚本,该脚本获取根目录中所有文件和文件夹的文件属性和ACL,并为根目录中的每个文件夹(文件夹A,文件夹B等)启动一个作业,并且该脚本不会出现任何错误.我尝试为每个文件夹(目录结构中的所有级别)创建作业,这又导致作业挂起或Powershell强制关闭. 我正在使用PowerShell V2.0,并且在我们的环境中无法对该版本进行任何升级.我是PowerShell的新手,如果这是一个非常愚蠢的问题,请原谅.

I have managed a script which gets the file properties and ACL of all the files and folders in the root and start a job for each of the folder in the root (Folder A, Folder B etc) which runs without any error. I tried creating jobs for each and every folder (all the levels in the directory structure) and this in turn results in to the job getting hung or the powershell getting force closed. I am using PowerShell V2.0 and any upgradation in the version is not possible in our environment. I am new to powershell and kindly forgive if it's a very silly question.

预先感谢您的帮助.

推荐答案

计算机上是否有可用的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

这篇关于用于get-childItem的PowerShell多线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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