Author Posts

May 31, 2018 at 7:53 pm

(PS5.1) I am trying to remotely uninstall software. I have tried the following:

$app = Get-WmiObject Win32_Product -computername "PC1" | where { $_.name -eq "softwarename" }
$app.Uninstall()

–And Also–

$application = Get-WmiObject Win32_Product -filter "Name='softwarename'" -ComputerName PC1 
	$application.Uninstall()

I am getting the following error:

You cannot call a method on a null-valued expression.
At line:2 char:2
+ $application.Uninstall()
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

I am not sure what this error is telling me. Can anyone shed some on this error?

Thank you

May 31, 2018 at 8:45 pm

Are you sure the resulting object has a method named uninstall()? Alternatively you could use Invoke-Command. Read the complete help including the examples to learn how to use.

May 31, 2018 at 10:25 pm

Your call is not returning anything. Hence the failure.

Validated by running this, as a admin on the localhost and those creds are in the local admin group on the remote host, on one of my lab machines

# Check for target application
($app = Get-WmiObject Win32_Product -Filter "Name = 'Adobe Reader XI (11.0.10)'" -ComputerName labpc01)


IdentifyingNumber : {AC76BA86-7AD7-1033-7B44-AB0000000001}
Name              : Adobe Reader XI (11.0.10)
Vendor            : Adobe Systems Incorporated
Version           : 11.0.10
Caption           : Adobe Reader XI (11.0.10)


# Remove target application
 $app.Uninstall()


__GENUS          : 2
__CLASS          : __PARAMETERS
__SUPERCLASS     :
__DYNASTY        : __PARAMETERS
__RELPATH        :
__PROPERTY_COUNT : 1
__DERIVATION     : {}

# Validate application was removed.
 ($app = Get-WmiObject Win32_Product -Filter "Name = 'Adobe Reader XI (11.0.10)'" -ComputerName labpc01)

June 1, 2018 at 1:44 am

I'd avoid Win32_Product. It's not very well coded, and although I'm not 100% sure why, querying it causes anything registered therein to be reevaluated. This integrity check can actually break things from time to time, and is both hard disk and processor intensive, completely unnecessarily.

Instead, query the registry locations for uninstall strings and execute them.

Another pain point of Win32_Product is that it simply doesn't list everything you may need. Adobe Acrobat may simply not exist in that class — which is probably why you're getting the error you're getting; Get-WmiObject returns $null when it doesn't find anything.

June 1, 2018 at 4:20 pm

Agreed on the Win32 class.
That whole Adobe this was just what I used as an example for locate and remove safely. The OP never listed the software they tried to hit.

June 1, 2018 at 5:55 pm

Thank you for the replies.
I have been tasked with removing various unsupported software packages that is on our network.
Trying to simplify software removal.