Simple replace command but trying to replace a $ with the British pound sign

Anthony H 21 Reputation points

Trying to replace the $ character using Power Shell Script. What to replace it with a £.
Instead of a £ I substituted a lower case z to keep it simple
PS M:\> $a = "My $ is not your $"
PS M:\> $a = $a -replace "`$","z"
PS M:\> $a
PS M:\> My $ is not your $z

I've tried various escape syntax and cannot seem to find the right combo.
I made sure the syntax works using non-special characters and it works like a charm but the $ seems to be problematic for me.

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,427 questions
0 comments No comments
{count} votes

Accepted answer
  1. Andreas Baumgarten 99,371 Reputation points MVP

    Hi @Anthony H ,

    please try this:

    $a = 'My $ is not your $'  
    $a = $a -replace "\$","z"  

    Output looks like this PS5.1 or PS7.1 :

    My $ is not your $  
    My z is not your z  

    Another one:

    $a = 'My $ is not your $'  
    $a = $a -replace "\$","€"  
    # Output:  
    My $ is not your $  
    My € is not your €  


    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Andreas Baumgarten

0 additional answers

Sort by: Most helpful