Increase Powershell script processing speed

I am currently using a Powershell script that reads all files and folders within a given path in order to trigger an archive recall. The script works fine, however, the speed in which it processes the reads are incredibly slow (approx. 1 file read every 4-5 seconds). Is there a way for me to increase the speed in which the script reads these files? A colleague of mine mentioned something about multi-threading.

My script is as follows:
Function Get-FolderItem {
    Param (
        [string[]]$Path = $PWD,
        [string[]]$Filter = '*.*',    
    Begin {
        $params = New-Object System.Collections.Arraylist
        If ($PSBoundParameters['MaxAge']) {
            $params.Add("/MaxAge:$MaxAge") | Out-Null
        If ($PSBoundParameters['MinAge']) {
            $params.Add("/MinAge:$MinAge") | Out-Null
    Process {
        ForEach ($item in $Path) {
            Try {
                $item = (Resolve-Path -LiteralPath $item -ErrorAction Stop).ProviderPath
                If (-Not (Test-Path -LiteralPath $item -Type Container -ErrorAction Stop)) {
                    Write-Warning ("{0} is not a directory and will be skipped" -f $item)
                If ($PSBoundParameters['ExcludeFile']) {
                    $Script = "robocopy `"$item`" NULL $Filter $params /XF $($ExcludeFile  -join ',')"
                } Else {
                    $Script = "robocopy `"$item`" NULL $Filter $params"
                Write-Verbose ("Scanning {0}" -f $item)
                Invoke-Expression $Script | ForEach {
                    Try {
                        If ($_.Trim() -match "^(?<Size>\d+)\s(?<Date>\S+\s\S+)\s+(?<FullName>.*)") {
                           $object = New-Object PSObject -Property @{
                                FullName = $matches.FullName
                            Write-Output $object
                            Get-Content -LiteralPath $object.FullName -TotalCount 1 -Encoding Byte
                        } Else {
                            Write-Verbose ("Not matched: {0}" -f $_)
                    } Catch {
                        Write-Warning ("{0}" -f $_.Exception.Message)
            } Catch {
                Write-Warning ("{0}" -f $_.Exception.Message)

$1 = "\\nas\c$\fs_D0\Project_2004"

Get-FolderItem -Path $1

Open in new window

Vincent HoangAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jeremy WeisingerSenior Network Consultant / EngineerCommented:
You could try adding the /MT switch to your params. If robocopy is running slowly it should speed it up.

With the /MT switch, it defaults to 8 threads but you can specify up to 128 (e.g. /MT:24).
More info on the robocopy switches:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.