1

Hoping someone can give me an idea on how to proceed with the remaining script. The script is to get Version number of Installed Chrome from that build Build a string for the uninstall as shown below.

I'm stuck on the second part, fine on getting the version number.

  1. What would the logic be next to then iterate through each user profile to run the setup.exe from C:\Users[username]\appdata\Local\Google\Chrome\Application\90.0.4430.72\Installer. The error I am getting is unrecognized cmdlet on the { & $unin}

Thank you

#UserHives - Find all the user profiles in the registry
$UserHives = Get-ChildItem Registry::HKEY_USERS\ |Where-Object {$_.Name -match '^HKEY_USERS\\S-1-5-21-[\d\-]+$'}
$UserProfile = $Env:USERPROFILE

#
foreach($user in $UserHives)


{
    #1.Get Version Of chrome
     
     #1. PATH TO SEARCH FOR
     $Path = Join-Path $user.PSPath "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Google Chrome"

            If (Test-Path $Path){
                 $GetVersion = Get-ItemProperty -Path $Path | Select-Object -Property Version
                 $VersionInstalled = $GetVersion.Version

                 

                 #create uninstallstring
                 $UninString = "\Google\Chrome\Application\$VersionInstalled\Installer\setup.exe --uninstall --Channel --chrome --force-uninstall"
                 $unin = $UserProfile + "" + $UninString

                 If($VersionInstalled){ & $unin}
                 
                 }
            
        }
Yubz
  • 25
  • 4
  • Just some well-intended advice: make proper formatting and indentation a habit, and it will save you a ton of time toubleshooting and bugfixing. – marsze Apr 20 '21 at 21:13
  • Thanks @marsze yes that's been on my mind for a while and then when looking back at this last night. I'll get on this right away. – Yubz Apr 21 '21 at 08:54

1 Answers1

0

Quote from the docs:

The call operator does not parse strings. This means that you cannot use command parameters within a string when you use the call operator.

Pass the arguments separately:

$uninArgs = "--uninstall", "--Channel", "--chrome", "--force-uninstall"
$uninExe = "$UserProfile\Google\Chrome\Application\$VersionInstalled\Installer\setup.exe"
if ($VersionInstalled) {
    & $uninExe $uninArgs
}
marsze
  • 15,079
  • 5
  • 45
  • 61