How to rename a string that contains parenthesis?

Hi, I am very new to PowerShell and am currently only using it to rename bulk files which I am having success with.

However, I have hit a hurdle when I try and rename a string that uses parenthesis. I’m speculating that each parenthesis may need to have a special character before and after it; however, I am not sure which special character it may be. Does anyone have any idea what it could be?

For example,
Dir | Rename-Item –NewName { $.name -replace “Old (Name)”,“New Filename” }
Dir | Rename-Item –NewName { $
.name -replace “(Old Name)”,“New Filename” }

Hey there and welcome.

Try this:

$Folder = Get-Item  -Path '.\(Old Name)'
$Folder | Rename-Item -NewName 'New Name'

NewName takes a string not a script block. Looks like what you’re attempting to do is get the item and use powershell pipline to rename it, which is what my code above does.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.