How to use operator ‘-replace’ in PowerShell to replace strings of texts with special characters and replace successfully

I have a script where I am basically doing a find and replace on several strings of text. The first couple of strings work, but when I do the account keys, they do not. How can I fix this problem?

Here is the script:

Get-ChildItem "[FILEPATH]" -recurse |
    Foreach-Object {
        $c = ($_ | Get-Content)
        $c = $c -replace 'abt7d9epp4','w2svuzf54f'
        $c = $c -replace 'AccountName=adtestnego','AccountName=zadtestnego'
        $c = $c -replace 'AccountKey=eKkij32jGEIYIEqAR5RjkKgf4OTiMO6SAyF68HsR/Zd/KXoKvSdjlUiiWyVV2+OUFOrVsd7jrzhldJPmfBBpQA==','DdOegAhDmLdsou6Ms6nPtP37bdw6EcXucuT47lf9kfClA6PjGTe3CfN+WVBJNWzqcQpWtZf10tgFhKrnN48lXA=='
        [IO.File]::WriteAllText($_.FullName, ($c -join "`r`n"))
    }

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)