0

I have the following problem:

I try to get all uninstallable applications from the registry and use (gp 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*').DisplayName -Like '*' as command. In the x86 version of Powershell it returns a list of the applications but in the x64 version I get this error:

PS C:\Users\simon> (gp 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*').DisplayName -Like '*'
gp : Die angegebene Umwandlung ist ungültig.
In Zeile:1 Zeichen:2
+ (gp 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*').Di ...
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-ItemProperty], InvalidCastException
    + FullyQualifiedErrorId : System.InvalidCastException,Microsoft.PowerShell.Commands.GetItemPropertyCommand

The gp command itself seems to work. Also the command above works in x64 Powershell on other systems.

What I've tried:

  • gp to verify the Powershell knows this command.
  • [intPtr]::size to check if its x86/x64
  • Reinstalled Powershell (via optionalfeatures.exe)
  • Installed a new .NET framework
  • Tried the commands on other systems (they work)
  • Run Powershell as admin
  • Changed the path (as env variable) for Powershell.exe (to use x86 as default, but this lead to other problems - nevermind)

I am out of ideas and also Google didn't get me further.

[SOLUTION]

I found out this error was caused by an invalid REG_DWORD-value for the property NoModify of a NetBeans installation in the registry.

markalex
  • 8,623
  • 2
  • 7
  • 32
Fenrir
  • 41
  • 7
  • What do you get if you just run `Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*'` ? From the error it seems that it's maybe not translating "HKLM:" as a registry path – Scepticalist Apr 01 '21 at 09:35
  • Could be that you need to use WOW6432Node as for example in this answer: https://stackoverflow.com/questions/57093792/how-to-access-a-64bit-registry-key-using-32bit-powershell-without-redirection-to – andr3yk Apr 01 '21 at 09:37
  • @Scepticalist: I get a stack of information for 3-4 applications and then the same InvalidCastException. In the x86-Powershell I got all applications returned. To andr3yk: I know that the x86/x64 use different registry-entries, but I don't believe this has something to do with the InvalidCastException. – Fenrir Apr 01 '21 at 11:53
  • are you running the x86 or the x64 version of PowerShell on Windows x64 ? – CFou Apr 01 '21 at 11:56
  • @CFou: x64 per default. I use the x86 just to check if the error occurs there too. I does not. – Fenrir Apr 01 '21 at 11:58
  • 2
    Since it's not all of them and is specific to this one mahcine then if you go find what registry entry that causing the invalid cast then you'll be halfway to finding why it does so. Use Try...Catch to display the error causing entry and keep running the command – Scepticalist Apr 01 '21 at 12:27

0 Answers0