Forum Discussion

robmo's avatar
robmo
Brass Contributor
Jan 25, 2023

Remove extra set of double quotes in string

Hi,

I am writing a PowerShell script that needs to remove Firefox that is less than or equal to a specific version. I have the script working up to where it reads the uninstall string from the registry. The uninstall string in the registry for Firefox already has double quotes. When I assign the uninstall string to a variable, another set of double quotes is added which is causing Test-Path to fail.

 

How do I efficiently remove the extra set of double quotes so Test-Path is able to do a proper check for the existence of the path?

 

Value as seen in the registry (one set of double quotes):

Value after assigning UninstallString to a variable (two sets of double quotes):

Error thrown by PowerShell:

 

Thank you!

Rob

  • I did some inspection of Firefox installations and it turns out that they use the same uninstall string for every version. The only difference is if helper.exe is in Program Files (x86) or Program Files:

    C:\Program Files (x86)\Mozilla Firefox\uninstall\helper.exe OR
    C:\Program Files\Mozilla Firefox\uninstall\helper.exe

    Since I have this information, I will just set some variables for these strings and then I won't have to deal with string handling when reading from the registry. This will simplify the development of this script.

    Thank you for your help!
    • robmo's avatar
      robmo
      Brass Contributor

      Harm_Veenstra,
      What would be a good way to test if this solution works? I am using the following code but it fails at the initial assignment on Line 1 and throws an error:

      $uninstall = ""C:\Program Files\Mozilla Firefox\uninstall\helper.exe""
      $uninstall = $uninstall -replace('""'),('"')
      $uninstall

       

      Perhaps I need to use string handling at the time the value is retrieved from the registry?

      • Ah, ok.. You should use $uninstall='"C:\Program Files\Mozilla Firefox\uninstall\helper.exe"' to escape the double "

Resources