I have been trying to write a script to remove end part of the filename and replace it with a version number of a build. I have tried trim and split but because of extra dots and not good with regex, im having problems.
These are file examples:
Filename.Api.sow.0.1.1856.nupkg
something.Customer.Web.0.1.1736.nupkg
I want to remove 0.1.18xx
from these filenames and add a build number from variable. which would be something like 1.0.1234.1233
(major.minor.build.revision)
so the end result should be:
Filename.Api.sow.1.0.1234.1233.nupkg
something.Customer.Web.1.0.112.342.nupkg
Here is my try to split and then rename. But it doesnt work.
$files = Get-ChildItem -Recurse | where {! $_.PSIsContainer}
foreach ($file in $files)
{
$name,$version = $file.Name.Split('[0-9]',2)
Rename-Item -NewName "$name$version" "$name".$myvariableforbuild
}