0
Get-ChildItem "\\myfileserver\files\folder\999\*" | Rename-Item -NewName { ($_.Name-replace '(?<=^[^_]+)_.+?(?=\.)').Replace(".vfmpclmadj.", ".va.").Replace(".VFMP.",".va.") }

The above changes the file name

Before 999_837I.84146.VFMP.000000384.20210127.121415

After 999.84146.va.000000384.20210127.121415

Now I need to remove 20210127.121415

and add the current date and time.

I need help accomplishing that last piece. Thanks.

mklement0
  • 382,024
  • 64
  • 607
  • 775
user770022
  • 2,899
  • 19
  • 52
  • 79

1 Answers1

1

Append another -replace operation:

# Remove the '.20210127.121415' suffix.
PS> '999.84146.va.000000384.20210127.121415' -replace '(\.\d+){2}$'
999.84146.va.000000384

Then re-append a timestamp string suffix in the same format based on the current point in time:

PS> '999.84146.va.000000384' + '.' + (Get-Date -Format yyyyMMdd.HHmmss)
999.84146.va.000000384.20210127.165325  # e.g.

Or, preferably, as part of a single -replace operation:

'999.84146.va.000000384.20210127.121415' -replace '(\.\d+){2}$', ".$(Get-Date -Format yyyyMMdd.HHmmss)"
mklement0
  • 382,024
  • 64
  • 607
  • 775
  • If I wanted to change the timezone can you show what that looks like? – user770022 Jan 28 '21 at 01:51
  • @user770022: [This answer](https://stackoverflow.com/a/59885215/45375) may help; if it doesn't, please ask a _new_ question; if so, feel free to notify me here once you've posted the new question, and I'll be happy to take a look. – mklement0 Jan 28 '21 at 02:13