Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Uninstall Chrome - worked once

$
0
0

I have a Powershell script I've written that "builds" a complete computer from just the basic Windows 7 Pro operating system with an Administrator account and a few programs already pre-installed (i.e., Chrome) and my script adds users, other programs, et al.  In this script, I have this section which removes any instance of Chrome -

$app = Get-WmiObject -Class Win32_Product | Where-Object {$_.Name -match "Chrome"}
   
$app.Uninstall()

Works just fine.  And a little bit later in the script, I install the newer version with this line -

$result = Start-Process -Wait -FilePath 'C:\ChromeStandaloneSetup.exe' -ArgumentList '/silent /install' -PassThru

Now these PCs are all out in the field (remote locations all over the country) and for PCI compliance, I need to upgrade their version of Chrome.  I have written a short Powershell script to once again remove any instances of Chrome and then use the Chrome standalone installer to put in the latest version of Chrome just as before with the same three lines -

$app = Get-WmiObject -Class Win32_Product | Where-Object {$_.Name -match "Chrome"}
   
$app.Uninstall()

$result = Start-Process -Wait -FilePath 'C:\ChromeStandaloneSetup.exe' -ArgumentList '/silent /install' -PassThru

However, at the $app.Uninstall() line, I get the error "You cannot call a method on a null-valued expression."  And it leaves me with the older version of Chrome when I check "Programs and Features".  So why did this uninstall work the first time, but is not working the second time?


Viewing all articles
Browse latest Browse all 6937

Trending Articles