0

I am trying to uninstall a Program via Power Shell but I am getting an error "You cannot call a method on a null valued expression.

PS C:\Users\user> $App = Get-WmiObject -Class Win32_Product | Where-Object{$_.Name -eq "CVF_x64"}
PS C:\Users\user> $App.Uninstall()
You cannot call a method on a null-valued expression.
At line:1 char:1
+ $App.Uninstall()
+ ~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

The program is in Programs and Features on control panel, see attached picture below. List of Apps on Control Panel

Powershell List of Apps CVF Doesn't show up in Powershell for some reason

3
  • 2
    Did you make sure that $App has something in it? Commented Sep 2, 2022 at 22:27
  • Could you list the items before filtering it with where. I wonder what have you got in there. I think you are getting null at the end Commented Sep 2, 2022 at 22:28
  • Just Updated it with the images, Powershell list of apps and list of apps on control panel, idk why it doesn't show CVF in powershell. Commented Sep 3, 2022 at 1:07

1 Answer 1

2

looks like your query does not find anything -> empty variable?

$x = $null
$x.uninstall()
result: You cannot call a method on a null-valued expression.

btw. wmi is a thing of the past, use the cim cmdlets, and do the filtering one step earlier:

$name = "MyApp"
get-ciminstance -query "select * from win32_product where name = '$name'"

To identify what the value of the variable name must be simply output this beforehand and identify the exact string:

(get-ciminstance -query "select * from win32_product").name

You could also check the registry:

HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall

Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*" -Name DisplayName,DisplayVersion,InstallSource,Publisher,UninstallString

Execute the command in the attribute UninStallString...

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

Comments

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.