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