Replace square bracket using Powershell

Question:

If you have a filename such as “Committee minutes [October 2010] – hq.doc”, how do you get Powershell to replace the square brackets? The following doesn’t work:

I get the error:

Answer:

Unfortunately this is a known bug/limitation of PowerShell. A suitable and actually not bad workaround is to use Move-Item for renaming items: it has the -LiteralPath parameter which is missing in Rename-Item.

See reported issues:

https://connect.microsoft.com/PowerShell/feedback/details/277707/rename-item-fails-when-renaming-a-file-and-the-filename-contains-brackets

https://connect.microsoft.com/PowerShell/feedback/details/553052/rename-item-literalpath

Source:

Replace square bracket using Powershell by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply