Reputation: 2959
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.
Upvotes: 0
Views: 136
Reputation: 437608
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)"
Upvotes: 1