add at the end of the log the number of files treat, remaining and errors

Hello,


How can I add at the end of the log the number of files treat, remaining and errors, please ?

ForEach-Object {
		$Directory = $_.Group
		$PrefixList | ForEach-Object {
			$Prefix = $_
			$Directory | Where-Object {$_.Name -like $Prefix} | Sort-Object -Property Name | Select-Object -First 1 | ForEach-Object {
				$NewName = $_.BaseName.SubString(1) -replace '_\d{8}_\d{6}\Z'
				Try {
					Rename-Item -Path $_.FullName -NewName $NewName -ErrorAction Stop -WhatIf
					$Result = 'OK'
				} Catch {
					$Result = $_.Exception.Message
				}
				$_ | Select-Object 'DirectoryName', 'Name', @{n='NewName'; e={$NewName}}, @{n='Result'; e={$Result}}
			}
		}
	} | Format-Table -AutoSize | Out-String -Width 1024 | Out-File E:\log.txt -Encoding Default -ErrorVariable ERR1 -Append

Open in new window

     
Thanks

Regards
bibi92Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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

oBdACommented:
You should post the complete script; the first two lines were missing, which is kind of confusing for Experts who don't know the background.
That said, since I know the background, try this:
$PrefixList = 'ZCAMER*', 'ZTOGO*'
$Log = 'D:\Files\log.txt'
$Total = $Processed = $Errors = 0
Get-ChildItem -Path D:\Files -Include $PrefixList -Recurse |
	Group-Object -Property DirectoryName |
	ForEach-Object {
		$Directory = $_.Group
		$Total += $Directory.Count
		$PrefixList | ForEach-Object {
			$Prefix = $_
			$Directory | Where-Object {$_.Name -like $Prefix} | Sort-Object -Property Name | Select-Object -First 1 | ForEach-Object {
				$NewName = $_.BaseName.SubString(1) -replace '_\d{8}_\d{6}\Z'
				Try {
					Rename-Item -Path $_.FullName -NewName $NewName -ErrorAction Stop -WhatIf
					$Processed += 1
					$Result = 'OK'
				} Catch {
					$Result = $_.Exception.Message
					$Errors += 1
				}
				$_ | Select-Object 'DirectoryName', 'Name', @{n='NewName'; e={$NewName}}, @{n='Result'; e={$Result}}
			}
		}
	} | Format-Table -AutoSize | Out-String -Width 1024 | Out-File -Path $Log -Encoding Default -Append

$(
"Total:     $($Total)"
"Processed: $($Processed)"
"Errors:    $($Errors)"
"Remaining: $($Total - $Processed)"
) | Out-File -Path $Log -Encoding Default -Append

Open in new window

0

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
bibi92Author Commented:
Thanks regards
0
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
Powershell

From novice to tech pro — start learning today.