Just use a regex to match the S... and the R... parts then insert L001 between them
PS /tmp> Get-ChildItem -File -Filter *.fastq.gz | Rename-Item -NewName { $_.Name -replace '(S\d+)_(R\d+)', '$1_L001_$2' } -WhatIf What if: Performing the operation "Rename File" on target "Item: /tmp/PP-SD01_S1_R1.fastq.gz Destination: /tmp/PP-SD01_S1_L001_R1.fastq.gz". What if: Performing the operation "Rename File" on target "Item: /tmp/PP-SD025_S20_R2.fastq.gz Destination: /tmp/PP-SD025_S20_L001_R2.fastq.gz". What if: Performing the operation "Rename File" on target "Item: /tmp/PP-SD039_S22_R1.fastq.gz Destination: /tmp/PP-SD039_S22_L001_R1.fastq.gz". What if: Performing the operation "Rename File" on target "Item: /tmp/PP-SD039_S22_R2.fastq.gz Destination: /tmp/PP-SD039_S22_L001_R2.fastq.gz". What if: Performing the operation "Rename File" on target "Item: /tmp/PP-SD05_S1_R2.fastq.gz Destination: /tmp/PP-SD05_S1_L001_R2.fastq.gz". What if: Performing the operation "Rename File" on target "Item: /tmp/PP-SD09_S20_R1.fastq.gz Destination: /tmp/PP-SD09_S20_L001_R1.fastq.gz". PS /tmp>
Shorter version:
dir *.fastq.gz | ren -Ne { $_.Name -replace '(S\d+)_(R\d+)', '$1_L001_$2' } -wi
After verifying that the names are correct, remove -WhatIf/-wi to do the real renaming
cmd commandthen it's probably off-topic here because cmd runs on Windows only