Uninstall software remotely

(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" }

–And Also–

$application = Get-WmiObject Win32_Product -filter "Name='softwarename'" -ComputerName PC1 

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: (:slight_smile: , RuntimeException
    • FullyQualifiedErrorId : InvokeMethodOnNull

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

Thank you

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.

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

__GENUS          : 2
__CLASS          : __PARAMETERS
__RELPATH        :
__DERIVATION     : {}

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

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.

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.

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.