I'm having big troubles combining the rename with an if-condition. PS cannot rename when the file has the same name as before and won't do anything afterwards. Plus it's unable to rename recursively.
I wanna do sth like:
$entrys = Get-ChildItem -Recurse $myPath
foreach ($name in $entrys) {
$newName=$name.FullName -replace('[\,\/\*\+\#\~\-\=\^\°\$\%\&\<\>\|]','')
if (-not ($newName -like $name)) {
Rename-Item $name -NewName $newName
}
}
I found something similar here but they dont have any conditions there.
So how do I pipe into an if-condition before renaming, so I can pipe directly from get-childitem -recurse to if() then rename()
? Or is there another possibility?
Thanks for help