1

I need to get value for "UninstallString" in

Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall {1535CAA3-9F33-414E-8987-0365169BE741}

calling:

Get-Item -path HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{1535CAA3-9F33-414E-8987-0365169BE741}

results in Get-Item : A positional parameter cannot be found that accepts argument '1535CAA3-9F33-414E-8987-0365169BE741'.

1
  • you need to wrap the path in "". But even if you do that I don't think you can access the registry value like that. Commented Nov 10, 2022 at 19:38

3 Answers 3

1

To complement js2010's helpful answer, which notes that lack of quoting is your primary problem ({ and } are PowerShell metacharacters):

In PowerShell v5 and above, you can use the Get-ItemPropertyValue cmdlet to directly return the data associated with a registry key's value:

# Note the use of '...' around the registry path 
# and the value name UninstallString at the end.
Get-ItemPropertyValue 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{1535CAA3-9F33-414E-8987-0365169BE741}' UninstallString

As for what you tried:

An unquoted argument such as HKLM:\...\{1535CAA3-9F33-414E-8987-0365169BE741} is processed as follows:

  • Because {...} creates a script block, it is considered the start of a separate argument, and string 'HKLM:\...\' and script block {1535CAA3-9F33-414E-8987-0365169BE741} are passed as two arguments.

  • Because Get-Item didn't expect an extra (positional) argument, it complained accordingly, and used the string representation of the script block in its error message.

    • A script block's string representation is its verbatim content, excluding { and }, which you can verify with {1535CAA3-9F33-414E-8987-0365169BE741}.ToString()

As noted, quoting is the solution, and since the path contains neither PowerShell variable references nor subexpressions, using a single-quoted, i.e. verbatim string literal ('...') is best.

The (usually less desirable) alternative is to stick with an unquoted argument and use individual escaping of PowerShell metacharacters with ` (the so-called backtick); e.g.:
Write-Output HKLM:\...\`{1535CAA3-9F33-414E-8987-0365169BE741`}

Sign up to request clarification or add additional context in comments.

2 Comments

that explains why I it worked just fine for values without curly braces '{'. another lesson learned!
Glad to hear it, @yBother.
1

Something like this with quotes, since curly brackets look like a scriptblock to powershell:

get-itemproperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{013DB423-A8DE-4423-9E50-D45ED1041789}' uninstallstring | 
  % uninstallstring

MsiExec.exe /I{013DB423-A8DE-4423-9E50-D45ED1041789}

Although for an msi you can uninstall with this in powershell 5.1:

get-package *chrome* | uninstall-package

For other non-msi installs the uninstallstring is here. Usually you have to add an extra option like "/S" for silent uninstall.

get-package *firefox* | % { $_.metadata['uninstallstring'] }

"C:\Program Files\Mozilla Firefox\uninstall\helper.exe"

Comments

-1

As I commented you need to wrap the path in "" however that still won't work. To get a registry value in powershell use Registry::HKEY_LOCAL_MACHINE\... as the path. And once you get the RegistryKey object you can use GetValue(string name) to get the value of UninstallString. So your command would look something like this:

(Get-Item -path "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{1535CAA3-9F33-414E-8987-0365169BE741}").GetValue("UninstallString")

2 Comments

Good point about needing quoting, but a HKLM: path work just fine in PowerShell: there are two registry "drives" predefined in PowerShell HKLM: (HKEY_LOCAL_MACHINE) and HKCU: (HKEY_CURRENT_USER) - run Get-PSDrive -PSProvider Registry to verify.
Also note that in PSv5+ you can use Get-ItemPropertyValue: Get-ItemPropertyValue 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{1535CAA3-9F33-414E-8987-0365169BE741}' UninstallString

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.