Trying to remotely uninstall an app

Hello,

I'm fairly new to PS and I've been working on a script to uninstall an application from a remote machine.

this is what i have so far:

$computers = "COMPA"

foreach ($computers in $computers){

    invoke-command -computerName $computers -scriptblock {
    $app = (Get-WmiObject -Class Win32_Product | Where-Object {$_.IdentifyingNumber -match "CDD4495B-0424-42F0-8D89-70D47E21BD69"})
    $app.uninstall()
    }
}

however i get the following error when i run the script:

You cannot call a method on a null-valued expression.
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

any feedback would be great.

February 28th, 2014 9:40am

Do not use invoke command.

if($app=Get-WmiObject -Class Win32_Product -filter 'IdentifyingNumber="CDD4495B-0424-42F0-8D89-70D47E21BD69"' -computer COMPA ){
    $app.uninstall()
}else{
    Write-Host 'App not found'  -fore red
}

WMI is a remoting system without PowerShell remoting.
Free Windows Admin Tool Kit Click here and download it now
February 28th, 2014 10:14am

i modified your sample a little bit since i still can't get it to run remotely. Keeps saying app not found.

this is what i have now:

if($app=Get-WmiObject -Class Win32_Product -computername COMPA -filter 'IdentifyingNumber="{CDD4495B-0424-42F0-8D89-70D47E21BD69}"'){
    $app.uninstall()
}else{
    Write-Host 'App not found'  -fore red
}

When i run it from a remote powershell window thru ISE it works perfectly. Application is uninstalled.

However when i run it from my computer it still says App not found.


February 28th, 2014 2:14pm

i modified your sample a little bit since i still can't get it to run remotely. Keeps saying app not found.

this is what i have now:

if($app=Get-WmiObject -Class Win32_Product -computername COMPA -filter 'IdentifyingNumber="{CDD4495B-0424-42F0-8D89-70D47E21BD69}"'){
    $app.uninstall()
}else{
    Write-Host 'App not found'  -fore red
}

When i run it from a remote powershell window thru ISE it works perfectly. Application is uninstalled.

However when i run it from my computer it still says App not found.


I don't believe you. 

Run this and tell me what you see:

Get-WmiObject -Class Win32_Product -computername COMPA -filter 'IdentifyingNumber="{CDD4495B-0424-42F0-8D89-70D47E21BD69}"'

Be sure the computername is the correct remote PC.

Free Windows Admin Tool Kit Click here and download it now
February 28th, 2014 2:33pm

returns nothing

I can see the CPU usage on the remote machine spike wile the script is running as well.

February 28th, 2014 2:37pm

could these be because i am trying to run the script from ISE and not a native powershell window?

remote vs my PS VersionTables

Free Windows Admin Tool Kit Click here and download it now
February 28th, 2014 2:43pm

Shouldn't matter.

Try this and look for the number:

Get-WmiObject -Class Win32_Product -computername COMPA  | select caption, IdentifyingNumber

February 28th, 2014 3:21pm

I get results for applications installed however the one i'm looking for isn't listed.

I did trying running the script from another computer to the same remote client and it works fine.

Leads me to believe something is wrong on my pc.  i have since uninstalled PS4 and PS3 completely and reinstalled PS3.  I still have the same issues running it from my pc.

This is the partial output from your command:

PS U:\powershell> Get-WmiObject -Class Win32_Product -computername COMPA| select caption, IdentifyingNumber

caption                                                     IdentifyingNumber
-------                                                     -----------------
Microsoft Office Access database engine 2007 (English)      {90120000-00D1-0409-0000-0000000FF1CE}
Microsoft Office File Validation Add-In                     {90140000-2005-0000-0000-0000000FF1CE}
Microsoft Network Monitor 3.4                               {8C5B5A11-CBF8-451B-B201-77FAB0D0B77D}
Microsoft Visual C++ 2010  x64 Redistributable - 10.0.40219 {1D8E6291-B0D5-35EC-8441-6616F567A0F7}

Free Windows Admin Tool Kit Click here and download it now
February 28th, 2014 4:04pm

So what you have proven is that this is not a scripting issue.  It is either break/fix or configuration.
February 28th, 2014 4:36pm

could these be because i am trying to run the script from ISE and not a native powershell window?

remote vs my PS VersionTables

  • Edited by Lonely_Tech Friday, February 28, 2014 7:44 PM
Free Windows Admin Tool Kit Click here and download it now
February 28th, 2014 10:40pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics