Right, this is quite similar to a previous query..
I am writing a script and I want it to check an MSI to see if any version is installed already and if it is, remove all versions already installed and install the new one..
I can run
msiexec.exe /x $FilePath /quiet
Which will uninstall that version if its already installed but not other versions of the software.. I was advised by a peer I was best using the uninstall string to remove all versions. So to find the Uninstall string for a particular product I wrote..
Get-ChildItem 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\' | foreach { gp $_.PSPath } | ? { $_ -match "Blah Blah Blah" } | select UninstallString
This brings out the uninstall string for the searched product that's installed.. Which shows up in this case something like
MsiExec.exe /I{XXXX9XXX-99X9-9X99-X999-9XX999999999}
Running that doesn't work though, it doesn't uninstall anything.. Why isn't it uninstalling the versions installed?
Also, I found that uninstall string by searching "Product Name" and im trying to automate this process when I pick up the MSI.. Is there anyway when I pick up the MSI to have the system search the registry and recognize if any versions of that product are already installed? If so, then to uninstall them?
I wrote -
$Namex = Get-ItemProperty $filepath | select name Get-ChildItem 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\' | foreach { gp $_.PSPath } | ? { $_ -match "$namex" } | select UninstallString
The value of $Namex is for argument sake 'Blah Blah Blah 8.3.5.0 installer.msi' and using the above code doesn't return anything but say I cut the 8.3.5.0 installer.msi part off and manually wrote -
ChildItem 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\' | foreach { gp $_.PSPath } | ? { $_ -match "Blah blah Blah" } | select UninstallString
it would return the uninstall string..
Any Ideas or suggestions how this process could be automated?