I am trying to use Rename-Item
to remove trailing characters including the hyphen from a filename, ex. 123456.001.zip-4.22815.ren
to 123456-001.zip
.
Rename-Item -NewName ($_.Name.split('-')[0])
seems to be something I am missing after the split.
The split operation must be performed in a scriptblock (
{}
). A simple expression (()
) won't work.Add
-replace '^(\d+)\.', '$1-'
if you want the period replaced with a hyphen.