Uninstall Chrome silently using Powershell - powershell

I have the following PowerShell script, which I am using to get the uninstall string for Google Chrome, and then I want to uninstall it silently. Line 3 in the script will pop up the GUI uninstaller (so it seems like everything is correct thus far), but if I add "/qn" or "/quiet" to the argument list, the uninstall doesn't seem to run at all, even if I let it sit for a couple hours.
What am I missing?
$AppName = "Google Chrome"
$Chrome = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall | Get-ItemProperty | Where-Object {$_.DisplayName -match $($AppName)}
Start-Process -Wait -FilePath MsiExec.exe -Argumentlist "/X",$Chrome.UninstallString.TrimStart("MsiExec.exe /X")

If it's an msi you can use uninstall-package:
get-package *chrome* | uninstall-package -whatif

instead of trying to use /X and remove /X and other things, try the following
# Get the key to uninstall
$chromeUninstall = $Chrome.Pspath.Split("\")[-1]
Start-Process -Wait -FilePath MsiExec.exe -Argumentlist "/X $ChromeUninstall /quiet /norestart"
or even simpler would be,
Start-Process -Wait cmd.exe -ArgumentList "/c msiexec /X $ChromeUninstall /quiet /norestart"
/c - Carries out the command specified by string and then terminates
Note
On my system I get two uninstall strings. You might want to think about looping or selecting first one in the list with the use of [0]

Related

Powershell start-process firefox with website and wait until firefox or tab gets closed for next command

Im trying to start firefox with a website expecting input
after finalizing the input and closing firefox or the firefox tab
the next command should start.
I've tried several approaches, but the second command is allways excecuted befor the first ended
$proc = Start-Process -FilePath "C:\Program Files\Mozilla Firefox\firefox.exe" -ArgumentList "https://www.memotoo.com/de/my-addressbook-and-contacts.php?connected=1" -PassThru
Wait-Process -id $proc.id
powershell.exe "C:\temp\Memotoo-EMBROSERVER.ps1"
You can just add the -Wait switch like this:
Start-Process -FilePath "C:\Program Files\Mozilla Firefox\firefox.exe" -ArgumentList "https://www.memotoo.com/de/my-addressbook-and-contacts.php?connected=1" -Wait
powershell.exe -file "C:\temp\Memotoo-EMBROSERVER.ps1"
You need to add a Sleep statement between the two.

Specifying complete installation option when running msi from powershell

I am trying to automate the installation of gstreamer on windows using powershell
I have the msi file downloaded, and am installing it as shown below
PS C:\Users\Administrator> $path = "C:\Users\Administrator\Downloads\gstreamer-1.0-devel-mingw-x86_64-1.18.0.msi";
PS C:\Users\Administrator> Start-Process -Wait -FilePath $path -Argument "/qn"
However, this does not get me the complete installation, because it is only selecting the default arguments from the installer.
I need to specify for it to perform the complete installation, how can I modify my arguments? So that it selects "complete" installation and not "typical" like it does by default
These should work:
Start-Process -Wait -FilePath $path -Argument "/qn","Complete=1"
Start-Process -Wait -FilePath $path -Argument "/qn Complete=1"
I had the same problem, so I ran the Installer from power shell with and without the /qn argument and logged the process into two different files. Finally, I compared the result and I was able to find that for installing process using the UI it adds a property called INSTALLLEVEL, which is set to 1000 (don't know why this value yet). So, by adding the argument INSTALLLEVEL=1000 it installs the complete version.
Start-Process -Wait -FilePath gstreamer-1.0-mingw-x86_64-1.20.2.msi -Argument "/qn INSTALLLEVEL=1000"
I had tried below but it did not work
Start-Process -Wait -FilePath $path -Argument "/qn","Complete=1"
Start-Process -Wait -FilePath $path -Argument "/qn Complete=1"
While this is working fine for me.
Start-Process -Wait -FilePath gstreamer-1.0-mingw-x86_64-1.20.2.msi -Argument "/qn INSTALLLEVEL=1000"

Silently install multiple exe installers in one folder in PowerShell

I've been learning powershell just for a bit and i was wondering if let's say for example in "D:\installers" folder where i have let's say 15 installers(all inno Setup) it would be possible to run a silent install of all of those exes?
So far i've learnt how to run just one installer on silent which works perfectly fine. I just dont know how i would do it with multiple exes
Start-Process -Wait -FilePath 'D:\Installers\Installer.exe' -ArgumentList '/silent' -PassThru just for one installer
$installers = get-childitem "D:\Installers" -Filter "*Driver*.exe"
foreach($inst in $installers)
{
Start-Process -Wait -FilePath ($inst.FullName) -ArgumentList '/silent' -PassThru
}
Get-Childitem can be used to get the installers, and with foreach you can go through the results
You may modify the path follow yours and copy it to powershell (ensure to run as administrator).
Powershell will run them in sequence one after another.
Start-Process -FilePath 'D:\Installers\Installer1.exe' -Wait
Start-Process -FilePath 'D:\Installers\Installer2.exe' -Wait
Start-Process -FilePath 'D:\Installers\Installer3.exe' -Wait

Passing arguments as a variable when installing an MSI using Start-Process

I am new to Powershell and, of course, trying to learn on the fly for a project- No pressure, right! :-)
I am working on a script to run an MSI package in quiet mode, passing it an activation code as an argument, that I have to extract from an XML file.
So far, I have everything working except for getting Start-Process to run the MSI with the arguments being passed in a Variable.
Set-ExecutionPolicy Bypass -Force
[System.Xml.XmlDocument]$XML_Doc = new-object System.Xml.XmlDocument
$XML_Doc.load('c:\myfolder\Configinfo.XML')
$ActivationID = $XML_Doc.CONFIGINFO.SITEINFO.ACTIVATEID
write-host "Activation Id is: $ActivationID"
$InstallString = "`'/I C:\myfolder\myinstaller.msi akey="+'"'+$ActivationID+'"'''
#$InstallString = "`'/I C:\myfolder\myinstaller.msi akey=`"$($ActivationID)`"'"
write-host "$InstallString"'''
Start-Process msiexec.exe -ArgumentList $InstallString -Wait -NoNewWindow
#Start-Process msiexec.exe -ArgumentList '/I C:\myfolder\myinstaller.msi akey="12345678-abcd-1a1b-x9x1-a1b2c3d4e5f6"' -Wait -NoNewWindow
Above is the code I am working with now. The last line that is commented out is an activation string that works.
I have verified that $ActivationID is pulling back the correct value, and that $InstallString mirrors the argument list in the commented version of the Start-Process string.
Any help would be appreciated!
The Start-Process commands aren't necessary. PowerShell is a shell. It can run commands. Just put the commands you want to run directly in the script.
msiexec /i "C:\myfolder\myinstaller.msi" "AKEY=$ActivationID"
I quoted the parameters to msiexec.exe in case any of them contain spaces. PowerShell will automatically expand the $ActivationID variable into the string inside the double quotes.
Your ArgumentList is being passed incorrectly.
[Xml]$XML_Doc = Get-Content -Path 'C:\myfolder\Configinfo.xml'
$ActivationID = $XML_Doc.CONFIGINFO.SITEINFO.ACTIVATEID
Write-Host "Activation Id is: $ActivationID"
$Path = 'msiexec'
$ArgList = #('/i','"C:\path\file.msi"',"akey=`"$ActivationID`"")
Write-Host "$Path $ArgList"
Start-Process -FilePath $Path -ArgumentList $ArgList -Wait -NoNewWindow
First off, let me welcome you to Powershell! It's a great language and a great community gathered around a common cause.
Since you're new to the language, you can still learn new tricks and that's a good thing, because it's generally accepted that the Write-Host cmdlet is nearly always a poor choice. If you don't trust me, you should trust the inventor of Powershell.
Now that that's out of the way, we should look at your MSI command. With Powershell, we don't have to directly open msiexec, and we can call the MSI directly. I would break the path to the installer into its own variable, and then we can add all of our arguments on top of it. Also, don't forget the "/qn" switch which will actually make all of this silent. All in all, your new script will look something like this:
[System.Xml.XmlDocument]$XML_Doc = new-object System.Xml.XmlDocument
$XML_Doc.load('c:\myfolder\Configinfo.XML')
$ActivationID = $XML_Doc.CONFIGINFO.SITEINFO.ACTIVATEID
Write-Verbose "Activation Id is: $ActivationID"
$msipath = "C:\myfolder\myinstaller.msi"
$args = #("akey=$ActivationID", "/qn")
Write-Verbose "Install path is $msipath"
Write-Verbose "Activation key is $akey"
Start-Process $msipath -ArgumentList $args -Wait -NoNewWindow

Installing Software Using PowerShell Invoke Command

$cs = New-PSSession -ComputerName MACHINE -Credential DOMAIN\admin
Copy-Item -Path C:\Scripts\smart -Destination C:\smart -ToSession $cs
msiexec /i "C:\Smart\SMART.msi" NB_PROD_KEY=NC-2ADA2-F9RKE-AKAIA-BBB ACTIVATE_LICENSE=1 INSTALL_INK="" LAT_CONTENT="" PRINT_CAPTURE="" INSTALL_DOCCAM_DRIVERS="" CUSTOMER_LOGGING=1 /qnT="" INSTALL_SPU=2 CUSTOMER_LOGGING=0 /qn
Hi,
I'm struggling to get the syntax that runs with the MSI working above - I've worked with switches inside script blocks which invoke commands beforfe successfully but, not with those parameters which are from the program vendors help file.
I also tried:
Start-Process "msiexec.exe" -Argumentlist "/i "C:\smartmsi\SMART.msi" `
NB_PROD_KEY=NC-2ADA2-F9RKE-AKAIA-BBB ACTIVATE_LICENSE=1 INSTALL_INK="" LAT_CONTENT="" PRINT_CAPTURE="" INSTALL_DOCCAM_DRIVERS="" CUSTOMER_LOGGING=1 /qn
Totally confused how to install using the vendors commands within POwerShell, how can i nest each argument if it's not a switch?
I also tried using Splatter:
$params = '/i', "C:\smartmsi\SMART.msi",
'NB_PROD_KEY=NC-2ADA2-CEAM7-F9RKE', 'ACTIVATE_LICENSE=1',
'/qn'
& msiexec.exe #params
$LastExitCode
No joy - this app will install remotely as a regular install.
Thanks in advance
UPDATE:
Now, i've also tried this:
invoke-command -Session $session -ScriptBlock {
Start-Process -FilePath C:\windows\system32\msiexec.exe `
-ArgumentList "/i `"C:\smart\SMARTSuite.msi`" `"NB_PROD_KEY=NC-2ADA2`" ACTIVATE_LICENSE=1 INSTALL_INK=`"`" LAT_CONTENT=`"`" PRINT_CAPTURE=`"`" INSTALL_DOCCAM_DRIVERS=`"`" CUSTOMER_LOGGING=1 /qn"
}
Still not working. Installer appears for a second then drops off.
You have to escape `" if you want them to be interpreted inside a string which already uses double quotes else you break the string chaining :
Start-Process -FilePath msiexec -ArgumentList "/i `"C:\smartmsi\SMART.msi`" NB_PROD_KEY=NC-2ADA2-F9RKE-AKAIA-BBB ACTIVATE_LICENSE=1 INSTALL_INK=`"`" LAT_CONTENT=`"`" PRINT_CAPTURE=`"`" INSTALL_DOCCAM_DRIVERS=`"`" CUSTOMER_LOGGING=1 /qn"
You don't have to escape double quotes if the string is surrounded by simple quotes