Uninstall software remotely

Welcome Forums General PowerShell Q&A Uninstall software remotely

This topic contains 5 replies, has 4 voices, and was last updated by

9 months, 2 weeks ago.

  • Author
  • #101559

    Points: 4
    Rank: Member

    (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: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

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

    Thank you

  • #101565

    Points: 1,077
    Helping Hand
    Rank: Community Hero

    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.

  • #101568

    Points: 1,071
    Helping Hand
    Rank: Community Hero

    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
    __SUPERCLASS     :
    __DYNASTY        : __PARAMETERS
    __RELPATH        :
    __DERIVATION     : {}
    # Validate application was removed.
     ($app = Get-WmiObject Win32_Product -Filter "Name = 'Adobe Reader XI (11.0.10)'" -ComputerName labpc01)
  • #101569

    Points: 433
    Helping Hand
    Rank: Contributor

    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.

  • #101601

    Points: 1,071
    Helping Hand
    Rank: Community Hero

    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.

  • #101610

    Points: 4
    Rank: Member

    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.

The topic ‘Uninstall software remotely’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort