'(PowerShell) Rename multiple files to include "MM_YYYY", "File 1 in XX" and "number of lines"

How can I rename multiple files in a folder to include :

  • MM_YYYY
  • File 1 in XX
  • Number of lines in the file

Example :

Current file name :

  • SRA_0400041325.TXT
  • SRA_0400027561.TXT
  • SRA_0400013497.TXT

After :

  • SRA_0400041325_03_2022_1-3_720.TXT
  • SRA_0400027561_03_2022_2-3_433.TXT
  • SRA_0400013497_03_2022_3-3_1720.TXT

How to do that in PowerShell ?

Thanks.

EDIT 1 :

I've tried this :

$Month = (Get-Date).ToString("MM")
$Year = (Get-Date).ToString("yyyy")
$MonthYear = $Month + "-" + $Year

$NumberOfFiles = (Get-ChildItem | Measure-Object).Count

$NumberOfLines =  Get-Content SRA_0400041325.TXT | Measure-Object -line | Select-Object -ExpandProperty Lines


$PartToAdd = $MonthYear + "_" + $NumberOfFiles + "_" + $NumberOfLines
Write-Host $PartToAdd

But I don't know how to include a ForEach



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source