This worked for me but I am wondering if there is a way I can run it and remove text before and after stuff and how to do it. Our file names come in from our vendor in this format:
TA-G01-004-Q-G-A091020.pdf
I want to remove everything and keep only the 01-004-Q in the middle but that number will be different per file name as well as the 091020 number. Im not quite sure how to put in the wild card in order to put maybe the first or second number and let it find the rest before the .pdf extension.
Secondly, is there a way I can write this into a batch file to where all I need to do is copy the files into that folder and run the file to rename everything?
Assuming the part you want always starts with a single letter
# Get part of filename then add date to said part
Get-ChildItem -Filter *.pdf | ForEach-Object {
$_.Name -match '\w(\d+-\d+-\w)' | Out-Null
$date = get-date -Format "MMM yyy"
# Use format operator to form new filename
$newname = "{0}_{1}{2}" -f $Matches[1],$date,$_.Extension
Rename-Item -Path $_.FullName -NewName $newname -Verbose
}