PowerShell Tip - Replace Text in Files that Might Have Square Brackets in Their File Names
June 18, 2015
# The -LiteralPath options are required if the filenames contain square brackets []
$items = Get-ChildItem -literalpath "{folder path}" -recurse
# enumerate the items array
foreach ($item in $items)
{
# if the item is a directory, then process it.
if ($item.Attributes -ne "Directory")
{
(Get-Content -LiteralPath $item.FullName ) |
Foreach-Object { $_ -replace '{old text}', '{new text}' } |
Set-Content -LiteralPath $item.FullName
}
}